normal distribution range
이전 댓글 표시
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
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
2011년 1월 27일
답변 (3개)
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
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
M ST
2011년 1월 27일
Andrew Newell
2011년 1월 27일
You could best thank Bruno by accepting the answer.
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
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
2011년 1월 27일
1 개 추천
Directly from the example in the documentation of randn:
r = 50 + 2.*randn(10000,1); hist(r,100)

Oleg
댓글 수: 3
M ST
2011년 1월 27일
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
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...
카테고리
도움말 센터 및 File Exchange에서 Normal Distribution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!