Why does entity generation stay at 0 after using randn function?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sebastian Stankiewicz
le 29 Juil 2017
Commenté : Jan
le 31 Juil 2017
I am using this code to try to generate random entities with the a mean of 100 and a std dev. of 10. Each time I try to run the simulation I get 0 entities generated and m=100 in the system dialog. How do I change the code to generate random entities?
persistent rngInit;
if isempty(rngInit)
seed = 12345;
rng(seed);
rngInit = true;
end
% Pattern: Gaussian (normal) distribution
% m: Mean, d: Standard deviation
m = 100, d = 10;
dt = m + d * randn;
1 commentaire
David Goodmanson
le 30 Juil 2017
Modifié(e) : David Goodmanson
le 30 Juil 2017
HI Sebastian, It might be worth looking at trying 'exist randn' (see 'help exist' at some opportune places in the code. If the answer is 5, it's hard to see how what you got could not work, but if it's ~=5 then something is not right.
Réponse acceptée
Walter Roberson
le 30 Juil 2017
If your dt is coming out empty, then at some point you assigned [] to randn
2 commentaires
Jan
le 31 Juil 2017
You can check the value of randn:
which randn -all
If you have defined
randn = []
anywhere and use scripts, the original function is "shadowed". Either remove the definition as a variable:
clear randn
or use functions, which have the great benefit compared to scripts, that they do niot import any typo from the command window and all other scripts.
Plus de réponses (1)
John BG
le 30 Juil 2017
Modifié(e) : John BG
le 30 Juil 2017
Chema Sebastian
1. tried randn in MATLAB online
N=12;
mu = 100*ones(N,1);
sigma = 10*ones(N,1);
z = mu+ randn(N,1).*sigma
z =
121.1303
96.8988
96.5285
86.7920
102.1630
105.4597
113.7002
108.0667
106.5743
102.7673
112.2676
104.2776
2.
checked rng status
scurr=rng
scurr =
struct with fields:
Type: 'twister'
Seed: 12345
State: [625×1 uint32]
3.
provided randn is told to generate N different random values.
Otherwise, when not passing arguments to randn
N=12;
mu = 100*ones(N,1);
sigma = 10*ones(N,1);
z = mu+ randn*sigma
z =
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
88.4374
randn only spins the roulette once.
4.
In any case the result is not empty.
When you say 'empty' do you really mean 'not random'?
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
0 commentaires
Voir également
Catégories
En savoir plus sur Discrete-Event Simulation 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!