sum contents of array in groups of 10

11 ビュー (過去 30 日間)
C.G.
C.G. 2021 年 1 月 21 日
コメント済み: C.G. 2021 年 1 月 21 日
My code produces a variable 'grains' which is a 1x3001 double.
I want to sum together the numbers in the first 10 cells, and repeat this in blocks of 10 cells until the end and save these in a new variable.
Please could somebody provide me with a starting point?
  2 件のコメント
Stephen23
Stephen23 2021 年 1 月 21 日
3001 is not exactly divisible by 10: what do you want done with the last element?
C.G.
C.G. 2021 年 1 月 21 日
i dont want to include the last one

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

採用された回答

Stephen23
Stephen23 2021 年 1 月 21 日
Where V is your 1x3001 vector:
M = sum(reshape(V(1:3000),10,[]),1)
  1 件のコメント
C.G.
C.G. 2021 年 1 月 21 日
thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by