sum contents of array in groups of 10

6 visualizaciones (últimos 30 días)
C.G.
C.G. el 21 de En. de 2021
Comentada: C.G. el 21 de En. de 2021
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 comentarios
Stephen23
Stephen23 el 21 de En. de 2021
3001 is not exactly divisible by 10: what do you want done with the last element?
C.G.
C.G. el 21 de En. de 2021
i dont want to include the last one

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 21 de En. de 2021
Where V is your 1x3001 vector:
M = sum(reshape(V(1:3000),10,[]),1)

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by