Sum a value in a matrix
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 7 de Oct. de 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;
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!