How to get sum of columns even if the matrix is a row vector?

1 Ansicht (letzte 30 Tage)
I'd like to get the sum of columns in a matrix, but when the matrix has only one row, the SUM function gives the sum of all elements in the row. How can I skip that? The ideal solution will return the row vector itself.

Akzeptierte Antwort

Matt J
Matt J am 4 Okt. 2016
Bearbeitet: Matt J am 4 Okt. 2016
sum(theMatrix,1)

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices 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!

Translated by