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

 Accepted Answer

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

1 Comment

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

Sign in to comment.

More Answers (0)

Products

Release

R2020a

Tags

Asked:

TOK
on 31 Mar 2021

Commented:

TOK
on 31 Mar 2021

Community Treasure Hunt

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

Start Hunting!