normal distribution range

조회 수: 2 (최근 30일)
M ST
M ST 2011년 1월 27일
댓글: Steven Lord 2019년 1월 16일
Hello, I would like to use 'randn' create random numbers normally distributed. I noticed that it creates positive and negative numbers with mean 0.
How do I create only positive numbers, say within a range 1 to 100 with a mean of around 50 (std dev can be 2).
I noticed that we can specify the mean and std dev, but not the range. How can I specify the range too.
Thanks.
  댓글 수: 2
Andrew Newell
Andrew Newell 2011년 1월 27일
Why don't you want negative numbers? Strictly speaking, a normal distribution with bounds on it is not a normal distribution. However, in the example you provided, a negative number should be extremely rare.
M ST
M ST 2011년 1월 27일
This is for a problem that that has X number of items numbered from 1-X. We choose the numbers randomly (normally distributed). Since the items are numbered positive, I wanted my range to be from 1-X.
Thanks.

댓글을 달려면 로그인하십시오.

답변 (3개)

the cyclist
the cyclist 2011년 1월 27일
I encourage you to be very careful about your terminology. It is contradictory to say that your variable has a range from 1-100, and is normally distributed (because a truly normal distribution has infinite tails).
A distribution that is truly finite in extent, but can be made to look "normal-ish", is the beta distribution. For example, take a look at this:
>> hist(100*betarnd(5,5,10000,1),50)
Finally, it is not really clear to me whether this is a discrete or a continuous distribution. You mention "number of items", which suggests a discrete count. But the distributions being suggested are continuous. Is it OK to have 64.7 items?

Bruno Luong
Bruno Luong 2011년 1월 27일
Please take a look at my FEX submission.
% Generate 1000000 numbers with mean ~ 50, range = [1 100], std = 20
X = 50+TruncatedGaussian(20,[1 100]-50,[1 1e6]);
>> min(X)
ans =
1.0008
>> max(X)
ans =
99.9996
>> mean(X)
ans =
50.0717
>> std(X)
ans =
19.9901
>> hist(X)
% Bruno
  댓글 수: 4
Burak TASCIOGULLARI
Burak TASCIOGULLARI 2019년 1월 16일
Hi Bruno, I cannot use that formula because matlab does not define it. I use Matlab R2017a. Is it a problem of Matlab version
Steven Lord
Steven Lord 2019년 1월 16일
It's an add-on from the File Exchange, not a function in a MathWorks product.
You can follow the link Bruno posted to download it then install it. Alternately you can click on the "Add-Ons" button in the Toolstrip, search for "truncated gaussian", open the submission from Bruno, and add it to your installation using the Add button. In this second case, MATLAB will default to putting it on your MATLAB path.

댓글을 달려면 로그인하십시오.


Oleg Komarov
Oleg Komarov 2011년 1월 27일

Directly from the example in the documentation of randn:

r = 50 + 2.*randn(10000,1);
hist(r,100)

Oleg

  댓글 수: 3
Bruno Luong
Bruno Luong 2011년 1월 27일
[ I noticed this one ranges from 42-56. ]
Wrong. range of Gaussian is always [-Inf,Inf].
Most of the time you can believe in your eye. But sometime you won't.
Bruno
Oleg Komarov
Oleg Komarov 2011년 1월 27일
I just suggest:
1) Use Bruno's function
2) Play with the example I posted, augmenting the number of draws and changing stdev etc...

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by