Summation of specific range of matrix

2 views (last 30 days)
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

Accepted Answer

Ive J
Ive J on 2 Jan 2021
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

More Answers (0)

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!