Borrar filtros
Borrar filtros

Cumulatively sum numbers in an array between two indices

10 visualizaciones (últimos 30 días)
TOK
TOK el 31 de Mzo. de 2021
Comentada: TOK el 31 de Mzo. de 2021
Hi,
Lets say I have an array with 10 positions as in the picture, for example.
I want to add all the numbers between Index 4 and index 8, and get my answer of 150
What would be the best way of going about this?
Thanks

Respuesta aceptada

DGM
DGM el 31 de Mzo. de 2021
Something like this:
x=5:5:50
sum(x(4:8))
  1 comentario
TOK
TOK el 31 de Mzo. de 2021
Perfect, thank you very much. I knew it was something quite simple but I just couldn't find or work it out!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by