Can i save random data in specific file in order to use them for different simulations?

3 ビュー (過去 30 日間)
Hello all! In my program code i have such random variables,they change for each iteration.Also there is some functions are depending on.These functions will generate results. In order to compare 3 approaches , i should use same results so i want to ask you if it is possible to save results for "100 iterations" and still use them for different approaches. hope that all clear, Thanks in advance.
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 12 日
perhaps use rng() to set the random number seed so they use the same random numbers?
Maria
Maria 2023 年 2 月 12 日
Yes, I want to generate 100 different random variables and save them in specific matrices so I can use these variables for all scenarios in order to compare them using same values.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2023 年 2 月 12 日
Yes you can do it. Whether it is a good idea to handle the situation this way is a different question.
rng(12345);
NumIter = 100;
MatrixSize = [73 19];
for iter = 1 : NumIter
data = rand(MatrixSize);
filename = sprintf('Matrix%03d', iter);
save(filename, 'data');
end
  10 件のコメント
Maria
Maria 2023 年 2 月 13 日
@Walter Roberson i will rewrite the code in cell may it works
Maria
Maria 2023 年 2 月 16 日
@Walter Roberson thank you your for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by