how to do sum of element of multiple number in matlab?
3 views (last 30 days)
Show older comments
Commented: Putri Basenda Tarigan on 18 Nov 2020
If I have
m=[3 3 4 3 2 4 3]
then I want to calculate the sum of m(c) at the same time
but only give me one number. I want it to be 2 numbers. How to do this?
Thanks in advance
Rik on 18 Nov 2020
More Answers (1)
Edited: Timo Dietz on 18 Nov 2020
Not sure whether I got your issue. But in case you want to summarize all members of m starting at index 1, up to each member of c (containing indices of m) individually, you can do this:
b=arrayfun(@(x) sum(m(1:x)), c)
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!