How to Multiply a number to a row of matrix

4 views (last 30 days)
For example i have matrix
A = [ 1 2 3 ; 3 4 5]
I want to multiply 2 to the 2nd row of the matrix so i got
A = [ 1 2 3 ; 6 8 10]

Accepted Answer

Star Strider
Star Strider on 23 Dec 2017
Use bsxfun to multiply the first row by 1 (so it remains the same), and the second row by 2:
A = [ 1 2 3 ; 3 4 5];
A = bsxfun(@times, A, [1; 2])
A =
1 2 3
6 8 10

More Answers (1)

David Wilson
David Wilson on 26 Dec 2017
or if you have a recent version of Matlab, then one can avoid the cryptic bxfun with
>> A.*[1;2]

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!