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

matrix manipulation

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.

Best Answer

sum(theMatrix,1)