my random changes its values during running my code

7 ビュー (過去 30 日間)
heba raouf
heba raouf 2021 年 2 月 24 日
コメント済み: heba raouf 2021 年 2 月 26 日
i working on my matlab code to generate data size with specific mean and value. so i used the following syntax:
mu=30;var=100;
ts=mu+sqrt(var)*randn(1,10);
but each time i run the code, the number inside ts vector changes and i need it to constant.
this problem affect the remaining steps of code and make size changes.
any solution to this problem??

採用された回答

Hernia Baby
Hernia Baby 2021 年 2 月 24 日
編集済み: Hernia Baby 2021 年 2 月 24 日
You can generate random numbers that are repeatable with saving and restoring the generator setting.
rng(1,'twister');
mu=30;var=100;
ts=mu+sqrt(var)*randn(1,10);
ts
Detail:
  1 件のコメント
heba raouf
heba raouf 2021 年 2 月 26 日
thanks alot ... i tried the code and worked well

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by