summing columns based on certain interval
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
umberto kober
le 24 Mai 2021
Commenté : umberto kober
le 24 Mai 2021
hi
I need your help with summing columns based on certain interval
I could not find a solution already discussed. I have a matrix of size 153×10
I need to split the sum in 3 parts
the first part is the first 51 lines
the second is from line 53 to 102
the third sum is from line 104 to 153
thank you in advance
0 commentaires
Réponse acceptée
the cyclist
le 24 Mai 2021
The best answer will depend on what specifically you want the output to be, and also how generalizable the solution needs to be. So, for example ...
% Create some pretend input
rng default
M = rand(153,10);
% The output
sumM(1,:) = sum(M(1:51,:));
sumM(2,:) = sum(M(53:102,:));
sumM(3,:) = sum(M(104:153,:));
disp(sumM)
This does what you ask. But I expect it is not everything you want. But maybe? Give us more details.
Plus de réponses (1)
Torsten
le 24 Mai 2021
sum(sum(A(1:51,:)))
sum(sum(A(53:102,:)))
sum(sum(A(104:153,:)))
3 commentaires
the cyclist
le 24 Mai 2021
FYI, in R2018b or later, one could instead do
sum(A(1:51,:),'all')
and so on, rather than applying the sum() twice.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!