Add value in column to previous?

2 views (last 30 days)
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.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 15 Jan 2015
Edited: Azzi Abdelmalek on 15 Jan 2015
a=[1 1 1 1 1]
b=cumsum(a)
  1 Comment
matlabuser12
matlabuser12 on 15 Jan 2015
Edited: matlabuser12 on 15 Jan 2015
for some reason i thought that summed the whole column and never tried it. thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!