Hi, i want to sum each 3 columns of my array for any array dimension.
For example, Y array is the sum of each X array respectively to its color.
Need this to do sum for Nx150 array, so that it can turn into Nx50 array
Thanks!

 Réponse acceptée

David Hill
David Hill le 14 Oct 2021
m=movsum(x,3);
y=m(:,1:3:end);

3 commentaires

ang bn
ang bn le 14 Oct 2021
Modifié(e) : ang bn le 14 Oct 2021
I'm sorry, is "movesum" a new function? because i couldnt find it in my matlab (r2015a)
thanks
Edit:
I just knew we can do matlab online, and it works perfectly, thank you so much!
Walter Roberson
Walter Roberson le 14 Oct 2021
movsum is R2016a and newer
ang bn
ang bn le 14 Oct 2021
okay now I'll just do matlab online, maybe later I will install newer version
thanks!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 15 Oct 2021
reshape(x, size(x,1), 3, [])
now you can sum along the second dimension, and then reshape to remove the now-singular second dimension.

Catégories

Produits

Version

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by