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.

 채택된 답변

Rik
Rik 2021년 2월 28일

0 개 추천

You can do it with a for loop, but you should use cumsum instead.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 2월 28일

댓글:

2021년 2월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by