Sum of selected elements in Matrix
Afficher commentaires plus anciens
Hello,
For example, I have a 10x10 matrix. I need to find 1x1, 2x2, 3x3, 4x4 ... matrixes element sum, I couldn't find an answer with the sum command. Could you help.
Example;

Réponses (2)
Alan Stevens
le 11 Déc 2020
How about:
for i=1:10, S(i) = sum(sum(A(1:i,1:i))); end
where A is your 10x10 matrix and S contains the 10 sums.
Bruno Luong
le 11 Déc 2020
Modifié(e) : Bruno Luong
le 11 Déc 2020
A=rand(1000);
[m,n]=size(A);
G=max((1:m)',1:n);
s=cumsum(accumarray(G(:),A(:)))
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!