Saving data for each iteration in a for loop

5 views (last 30 days)
nathan stallworth
nathan stallworth on 13 Aug 2021
Commented: nathan stallworth on 13 Aug 2021
I am wanting to save the table data that is being written each loop, instead the data is being overwritten. I was going to try to do: info = [info output] that didn't work and I can't do info(i,:) = output because those deminsions do not line up. And the "table" varible I am not sure what I could do there to store all the data as oppsed to looping over it each time.
Thank you

Answers (2)

Yongjian Feng
Yongjian Feng on 13 Aug 2021
Your info needs to be initialized outside the loop, right?
  4 Comments
nathan stallworth
nathan stallworth on 13 Aug 2021
Resolved it, got everything in a cell then did vertcat with said cells.

Sign in to comment.


Cris LaPierre
Cris LaPierre on 13 Aug 2021
Edited: Cris LaPierre on 13 Aug 2021
You need to use indexing to assign the results of each loop to a new location. Look at this example on the for loop documentation page.
You may also want to consider going though Ch 13 of MATLAB Onramp.
  5 Comments
nathan stallworth
nathan stallworth on 13 Aug 2021
Sorry about that, I actually just got it using cells however then I had to figure out how concatinate vectors of different number of rows. Vertcat came handy there.
Thank for all the help

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!