How do I create a simple loop to sum up the elements in my matrix assuming some elements vary.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
George Adomako Kumi
am 13 Nov. 2021
Beantwortet: Dave B
am 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 Kommentare
Akzeptierte Antwort
Dave B
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!