Adding matrices
2 ビュー (過去 30 日間)
古いコメントを表示
I have an m by m by n set of matrices and I want to add all of the matrices in the n dimension so I would end up with only one m by m matrix. I have tried several different ways to do this but I just cannot come up with a set of code that does the addition for any number of n matrices.
1 件のコメント
Brett Shoelson
2011 年 2 月 9 日
What exactly do you mean by a set of matrices? Can you show the form of your data? Is this a cell array? Lots of separate variables?
採用された回答
Mahmoud Hammoud
2011 年 2 月 9 日
a = rand(2,2,2); asum = sum(a,3);
asum is the sum along the 3rd dimension.
0 件のコメント
その他の回答 (1 件)
Fangjun Jiang
2011 年 2 月 9 日
a=rand(2,3,4); b=sum(a,3)
b =
2.8451 2.1572 1.6369
1.9019 0.9626 2.0225
Is this what you want?
The trick is to read the help of sum()
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!