Cumulatively sum numbers in an array between two indices

10 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by