Sum groups of columns
조회 수: 8(최근 30일)
표시 이전 댓글
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
댓글 수: 0
채택된 답변
Turlough Hughes
2022년 9월 24일
Here's another option:
a = rand(10,4600);
b = mat2cell(a,height(a),repmat(50,1,width(a)/50));
result = cellfun(@(x) sum(x,'all'),b)
추가 답변(1개)
Davide Masiello
2022년 9월 24일
편집: Davide Masiello
2022년 9월 24일
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
댓글 수: 0
참고 항목
범주
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!