Summation of specific range of matrix

조회 수: 1 (최근 30일)
Victoria Pake
Victoria Pake 2021년 1월 2일
댓글: Victoria Pake 2021년 1월 2일
Dear all,
I have an 2464x2464 matrix and sorted by countries alpabethwise such that the first 56 rows represent a country, the 56 rows another and so on . i want to calculate the sum of the 56 rows per country such that i end up with a 44x1 matrix, which represent 1 value per country. I did it for the first country by using
Q_aus = sum(sum(Q_all(1:56,:),2))
How can I write a loop to do this for the whole matrix, without doing it by hand ?
Thanks in advance

채택된 답변

Ive J
Ive J 2021년 1월 2일
n = size(Q_all, 1)/56;
Q_aus = (0);
for i = 1:44
Q_aus(i, 1) = sum(sum(Q_all(56*i-55:56*i,:),2));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by