Sum a value in a matrix
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Ameer Hamza
le 7 Oct 2020
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;
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!