Sum groups of columns
Show older comments
Hello,
I have a 10x4600 matrix and I would like to sum all the content in 50 column groups, i.e., sum all of the contents in cols 1-50 then 51-100 etc., greating a 1x92 matrix.
What is the best way to do this?
Any advice is much appreciated
Accepted Answer
More Answers (1)
Davide Masiello
on 24 Sep 2022
Edited: Davide Masiello
on 24 Sep 2022
Example
M = rand(10,4600);
n = 50;
for idx = 1:size(M,2)/n
S(idx) = sum(M(:,n*(idx-1)+1:n*idx),'all');
end
size(S)
S
Categories
Find more on Creating and Concatenating Matrices 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!