Filter löschen
Filter löschen

Doublesum

1 Ansicht (letzte 30 Tage)
Brooke
Brooke am 15 Apr. 2012
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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by