Storing for loop using either zeros or ones?
3 views (last 30 days)
I have a 1000 data-sets from a for loop, but it only keeps the last value that was generated. Is there a simple way to store all the data from the for loop into an array. I've tried element multiplication using ones but it still only stores the last data set. Each value is 1x3.
Here is the output, in this case for vECI
Cris LaPierre on 3 Nov 2022
You overwrite your variable vECI in each loop, leaving you with just the final values. If you want to save the value from every loop, you need to assing the output using indexing.
What is the best way to do it will depend on what you do next with vECI. Compare b and c in the example below
for a = 1:3
c(a) = a;