How to use the sum function on a matrix to get the sum of the rows not the columns
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
daniel adams
am 29 Sep. 2021
Beantwortet: Steven Lord
am 29 Sep. 2021
How to use the sum function on an array to get the sum of the rows not the columns :
I want to have an array of the sum of the rows of a matrix ( dimension $nxn$ ). When I use the sum function I get a sum of the columns.
If my matrix is called M the following code gives me what I want
sum_of_the_rows=sum(M')
However, this requires taking a transpose, is there a faster way to do this?
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 29 Sep. 2021
Use the dim input argument. See the third example titled "Sum of Matrix Rows" on the documentation page.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!