How to use the sum function on a matrix to get the sum of the rows not the columns
1 回表示 (過去 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!