How do I create a simple loop to sum up the elements in my matrix assuming some elements vary.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
George Adomako Kumi
le 13 Nov 2021
Réponse apportée : Dave B
le 13 Nov 2021
Tp1 = [ E*A1 E*Sx1 E*Sy1 E*Sw1 ; E*Sx1 E*Ix1 E*Ixy E*Iwy; E*Sy1 E*Ixy E*Iy1 E*Iwx ];
To1 = [ 0 0 0 0; 0 0 0 0; 0 0 0 0] ;
Kt1=repmat({Tp1},128,128);
Kt1([28,48,50,124])={To1};
Kt1=cell2mat(Kt1);
0 commentaires
Réponse acceptée
Dave B
le 13 Nov 2021
You don't need a loop:
a = rand(3,4)
sum(a) % sum of each column, also sum(a,1)
sum(a,2) % sum of each row
sum(a,'all') % sum of all values, or sum(a(:)) on old releases
If you really want to do it in a loop:
s=0;
for i = 1:numel(a)
s=s+a(i);
end
s
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!