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

조회 수: 2 (최근 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 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