Cumulatively sum numbers in an array between two indices

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

 Réponse acceptée

Something like this:
x=5:5:50
sum(x(4:8))

1 commentaire

Perfect, thank you very much. I knew it was something quite simple but I just couldn't find or work it out!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2020a

Tags

Question posée :

TOK
le 31 Mar 2021

Commenté :

TOK
le 31 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by