Sum of the elements of rows of matrix
Mostrar comentarios más antiguos
lets say i have A=[1 2 1;3 2 1;3 5 4] and i want to sum up row elements separately and show me results as "Ri=..." here "i" is number of row. in this case R1=7, R2=9. R3=6.
1 comentario
Matt J
el 28 de Mayo de 2014
It sounds like you really mean "sum up column elements". The elements you are summing all belong to a common column, not a common row.
Respuesta aceptada
Más respuestas (2)
Chandrasekhar
el 28 de Mayo de 2014
0 votos
sum(A')
Jos (10584)
el 28 de Mayo de 2014
You do not want to store the results in separate variables R1, R2, etc., but rather as elements of a single variable R, with R(1), R(2), etc.
A = magic(3)
RowSum = sum(R,2)
help sum
2 comentarios
Akmyrat
el 28 de Mayo de 2014
Jos (10584)
el 28 de Mayo de 2014
What do you mean, "not working"? Did you read the help of sum?
May be you want to sum along rows rows, i.e., sum the elements in each column?
ColumnSum = sum(R,1)
Next time, be a little bit more specific ...
Categorías
Más información sobre Loops and Conditional Statements 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!