Doublesum
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have matrix with elements M(i,j,k) and I want to sum all the elements corresponding to a fixed k, how might I achieve that? In other words I would like to sum over two of the indices. Thank you.
0 件のコメント
採用された回答
Jan
2012 年 4 月 15 日
M = randn(10,10,3); % Arbitrary test data
P = M(:, :, 2); % Get submatrix, 3rd dimension is 2
P = P(:); % Reshape submatrix to a column vector
S = sum(P); % Sum over all elements of P
3 件のコメント
Jan
2012 年 4 月 15 日
I've added comments. The basics of Matlab are explained in the Getting Started chapters of the documentation.
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!