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

 채택된 답변

DGM
DGM 2021년 3월 31일
Something like this:
x=5:5:50
sum(x(4:8))

댓글 수: 1

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

TOK
2021년 3월 31일

댓글:

TOK
2021년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by