Add value in column to previous?

data_input=[1;1;1;1;1;1;1]
data_output=[1;2;3;4;5;6;7]
how can i achieve this with a for loop? basically take the preceding value and add it to the next one and then repeat as new values emerge.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 15 de En. de 2015
Editada: Azzi Abdelmalek el 15 de En. de 2015
a=[1 1 1 1 1]
b=cumsum(a)

1 comentario

matlabuser12
matlabuser12 el 15 de En. de 2015
Editada: matlabuser12 el 15 de En. de 2015
for some reason i thought that summed the whole column and never tried it. thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 15 de En. de 2015

Editada:

el 15 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by