How to use the sum function on a matrix to get the sum of the rows not the columns
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Steven Lord
2021년 9월 29일
Use the dim input argument. See the third example titled "Sum of Matrix Rows" on the documentation page.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!