Adding numbers in a row vector

5 views (last 30 days)
Ali Fuat Yuvali
Ali Fuat Yuvali on 28 Feb 2021
Commented: Ali Fuat Yuvali on 28 Feb 2021
How can I tell the computer to do this instead of manually typing it?
a = [1,2,3];
alist = [a(1),a(1)+a(2),a(1)+a(2)+a(3)]
Played around with a for loop but it didn't do what I wanted.

Accepted Answer

Rik
Rik on 28 Feb 2021
You can do it with a for loop, but you should use cumsum instead.

More Answers (0)

Categories

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!