How can I sum each 3 columns array?

4 ビュー (過去 30 日間)
ang bn
ang bn 2021 年 10 月 14 日
回答済み: Walter Roberson 2021 年 10 月 15 日
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!

採用された回答

David Hill
David Hill 2021 年 10 月 14 日
m=movsum(x,3);
y=m(:,1:3:end);
  3 件のコメント
ang bn
ang bn 2021 年 10 月 14 日
okay now I'll just do matlab online, maybe later I will install newer version
thanks!

サインインしてコメントする。

その他の回答 (1 件)

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

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by