Why does entity generation stay at 0 after using randn function?

1 view (last 30 days)
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 Comment
David Goodmanson
David Goodmanson on 30 Jul 2017
Edited: David Goodmanson on 30 Jul 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Jul 2017
If your dt is coming out empty, then at some point you assigned [] to randn
  2 Comments
Sebastian Stankiewicz
Sebastian Stankiewicz on 31 Jul 2017
Can this happen at any point? For right now this is the only code that I have in the script. If I had previously assigned [] to randn, would it have it saved?
Jan
Jan on 31 Jul 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.

Sign in to comment.

More Answers (1)

John BG
John BG on 30 Jul 2017
Edited: John BG on 30 Jul 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

Categories

Find more on Discrete-Event Simulation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!