Adding numbers in a row vector

4 visualizaciones (últimos 30 días)
Ali Fuat Yuvali
Ali Fuat Yuvali el 28 de Feb. de 2021
Comentada: Ali Fuat Yuvali el 28 de Feb. de 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.

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by