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

1 次查看(过去 30 天)
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 个评论
David Goodmanson
David Goodmanson 2017-7-30
编辑:David Goodmanson 2017-7-30
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-7-30
If your dt is coming out empty, then at some point you assigned [] to randn
  2 个评论
Sebastian Stankiewicz
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 2017-7-31
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.

请先登录,再进行评论。

更多回答(1 个)

John BG
John BG 2017-7-30
编辑:John BG 2017-7-30
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

类别

Help CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by