sum contents of array in groups of 10

조회 수: 8 (최근 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by