my random changes its values during running my code

8 vues (au cours des 30 derniers jours)
heba raouf
heba raouf le 24 Fév 2021
Commenté : heba raouf le 26 Fév 2021
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??

Réponse acceptée

Hernia Baby
Hernia Baby le 24 Fév 2021
Modifié(e) : Hernia Baby le 24 Fév 2021
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 commentaire
heba raouf
heba raouf le 26 Fév 2021
thanks alot ... i tried the code and worked well

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by