フィルターのクリア

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

1 回表示 (過去 30 日間)
Sebastian Stankiewicz
Sebastian Stankiewicz 2017 年 7 月 29 日
コメント済み: Jan 2017 年 7 月 31 日
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
Sebastian Stankiewicz 2017 年 7 月 31 日
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 Center および File ExchangeDiscrete-Event Simulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by