multiplying row vector by a scalar
显示 更早的评论
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!
回答(4 个)
the cyclist
2023-2-23
You needed a colon in place of that semicolon
A = data(3,:).*B
3 个评论
Kay
2023-2-23
John D'Errico
2023-2-23
They both told you how to do EXACTLY that. Did you try it?
Kay
2023-2-23
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,:)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!