简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM