How do I find the sum of every X rows in a matrix in Matlab

123 views Asked by At

I have a 189 x 4914 matrix and am trying to find the sum of each row in each 1x26 sub-matrix. How would I go about this?

Many thanks.

1

There are 1 answers

0
Luis Mendo On BEST ANSWER

Try this:

n = 26;
result = reshape(sum(reshape(x.', n, []), 1), [], size(x, 1)).';

You can look at intermediate results to see how this works: reshape(x.', n, []), then sum(reshape(x.', n, []), 1) etc