How to Multiply a number to a row of matrix
29 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
采纳的回答
Star Strider
2017-12-23
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
3 个评论
更多回答(1 个)
David Wilson
2017-12-26
or if you have a recent version of Matlab, then one can avoid the cryptic bxfun with
>> A.*[1;2]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!