Adding numbers in a row vector

4 Ansichten (letzte 30 Tage)
Ali Fuat Yuvali
Ali Fuat Yuvali am 28 Feb. 2021
Kommentiert: Ali Fuat Yuvali am 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.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by