for loop to sum values
조회 수: 2 (최근 30일)
이전 댓글 표시
I need to sum the value of
row column + row column + ... + row column
1 6,7,8 145 6,7,8 ... 6,7,8
2 6,7,8 146 6,7,8 ... 6,7,8
3 6,7,8 147 6,7,8 ... 6,7,8
... 6,7,8 ... 6,7,8 ... 6,7,8
144 6,7,8 288 6,7,8 52560 6,7,8
X=zeros(1,3);
x = 365
for i = 1:length(outDates(:,5))
avgspeeds = zeros(1,3);
for j = 1:3
sum1 = outDates(i,5+j) + outDates(i+n,5+j)
end
end
답변 (3개)
Jan
2022년 10월 15일
편집: Jan
2022년 10월 15일
what about the answer given to your similar question: https://www.mathworks.com/matlabcentral/answers/1826808-sum-of-values-in-matrix-with-a-loop#answer_1075888
No loop needed:
X = reshape(outDates(:, 6:8), 144, [], 3); % Reshape to 3D array
Y = squeeze(sum(X, 2) / size(X, 2)); % Mean over 2nd dimension
댓글 수: 0
Torsten
2022년 10월 15일
outDates = rand(52560,9);
sums = zeros(144,1);
for i=1:144
sums(i) = sum(outDates(i+(0:364)*144,6)) + sum(outDates(i+(0:364)*144,7)) + sum(outDates(i+(0:364)*144,8));
end
sums
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!