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

 採用された回答

KSSV
KSSV 2020 年 10 月 7 日

0 投票

A = zeros(4,3) ;
A(2,:) = 3 ;

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 7 日

0 投票

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!

Translated by