Is there a concise way of summing over multiple dimensions of an array?
19 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
Is there a concise way of summing over multiple dimensions, i.e. using just one sum function? I know if I have a defined array A, then I can do:
sum(A(:));
But what if I want to sum over a range of that array or some kind of calculated array? I would either have to use sum of sum of sum and so on to get the total sum or assign a variable to that temporary array? Thank you!
採用された回答
その他の回答 (2 件)
Pooja Lalan
2018 年 11 月 7 日
編集済み: Pooja Lalan
2018 年 11 月 7 日
Starting in R2018b, you can use this syntax
sum( SomeArray(1:18, 5:43, :, 2:9), 'all' )
sum( SomeArray(1:18, 5:43, :, 2:9), [1 2 3 4] )
0 件のコメント
Guillaume
2017 年 12 月 4 日
Not sure it is concise, it avoids the multiple sum:
sum(reshape(A(yourange), 1, []))
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!