Doublesum

1 次查看(过去 30 天)
Brooke
Brooke 2012-4-15
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.

采纳的回答

Jan
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
Jan 2012-4-15
I've added comments. The basics of Matlab are explained in the Getting Started chapters of the documentation.
Brooke
Brooke 2012-4-15
Thank you very much! :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by