Doublesum
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Jan
el 15 de Abr. de 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 comentarios
Jan
el 15 de Abr. de 2012
I've added comments. The basics of Matlab are explained in the Getting Started chapters of the documentation.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!