Sum groups of columns
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Millie Johnston
il 24 Set 2022
Commentato: Millie Johnston
il 24 Set 2022
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 Commenti
Risposta accettata
Turlough Hughes
il 24 Set 2022
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)
Più risposte (1)
Davide Masiello
il 24 Set 2022
Modificato: Davide Masiello
il 24 Set 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Detection in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!