multiplying row vector by a scalar
Show older comments
trying to multiply the third row of a matrix by another row, B:
A = data(3, ;).*B
where B is a row vector
Need help finding a way to multiply the 3rd row of my matrix by a scalar value, for example 100.
Is there a way to do this all in one line?
Thanks!
Answers (4)
the cyclist
on 23 Feb 2023
You needed a colon in place of that semicolon
A = data(3,:).*B
3 Comments
Kay
on 23 Feb 2023
John D'Errico
on 23 Feb 2023
They both told you how to do EXACTLY that. Did you try it?
Kay
on 23 Feb 2023
A = ones(4,3)
B = 1:3;
A(3,:) = A(3,:).*B
% Your matrix
M = magic(4)
% Your scalar
scalar = 100;
% Multiply the third row of your matrix by your scalar
M(3,:) = scalar .* M(3,:)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!