How do I create a simple loop to sum up the elements in my matrix assuming some elements vary.
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Dave B
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!