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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 11 月 3 日

0 投票

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
b=a;
c(a) = a;
end
b
b = 3
c
c = 1×3
1 2 3

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

質問済み:

2022 年 11 月 3 日

回答済み:

2022 年 11 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by