How do I create a simple loop to sum up the elements in my matrix assuming some elements vary.
조회 수: 2 (최근 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!