简体   繁体   English

如何在Matlab中找到矩阵中每X行的总和

[英]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.我有一个 189 x 4914 的矩阵,我试图找到每个 1x26 子矩阵中每一行的总和。 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您可以查看中间结果以了解其工作原理: reshape(x.', n, []) ,然后sum(reshape(x.', n, []), 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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