Sum a value in a matrix
古いコメントを表示
Hi!
How could I sum a value in a row of a Matrix? Imagine I have:
(0,0,0;0,0,0;0,0,0;0,0,0) and I would like to have (0,0,0;3,3,3;0,0,0;0,0,0)
How could I get this result?
Thank you
採用された回答
その他の回答 (1 件)
Ameer Hamza
2020 年 10 月 7 日
If you want to sum it to an arbitrary matrix row, then you can try the following methods
M = [1 2 3; 4 5 6; 7 8 9; 10 11; 12];
M_new = M + [0; 3; 0; 0];
This will add 3 to the second row of M. Similarly; you can also use the following equivalent statement
M_new = M;
M_new(2,:) = M_new(2,:)+3;
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!