How do I create a simple loop to sum up the elements in my matrix assuming some elements vary.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dave B
2021-11-13
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!