random normal distributed numbers

14 次查看(过去 30 天)
Andreas
Andreas 2012-7-6
Hello,
i have a quite simple question(at least i think so^^) but cant find the answer.
i want to produce numbers which are normal distributed. the numbers have to be in a range between a and b, where are 3 sigma of values(99,73%) have to be in that range. at the moment i have this:
a=1.4; %%%minimal Value
b=1.6; %%%maximal Value
c=(a+b)/2; %%%average
sigma=1;
R=normrnd(c,sigma,1,1000);
but i dont know how i can tell matlab that i want the value in the range of a to b? and that this range schould be contains 3sigma of the values.. maybe i have to use an other function? thanks for any help ;)

回答(3 个)

Andrei Bobrov
Andrei Bobrov 2012-7-6
BUT this is NOT normal distribution
k = randn(100,1);
a=1.4;
b=1.6;
m = min(k);
out = (k - m)*(b - a)/(max(k)-m) + a;

Andreas
Andreas 2012-7-6
okay, i have to look if this will help me, but at first its good to have something.
if anyone other has an idea how to make it with a normal distribution and the 99% range like in the start post please write ;)
but thanks for the help!
  1 个评论
AC
AC 2012-7-6
Is it ok if you get less than 1000 numbers in the end? Because you could just truncate your vector R up there. But you would end up with some 997 values in the end if your number is correct. (Actually I'm guessing you thought about that already, so I'm not sure...)

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-7-6
Normal distribution are defined to have infinite tails. If you have a constrained value range, then it is not normal distribution.
If you want to construct a normal distribution such that 3 sigma is between a and b, but values outside that range are still possible, then that is a different matter.
Remember, if 99.73% is within the range a to b, then if you select 1000 random values, then on average 2.7 of the results will be outside a to b

Community Treasure Hunt

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

Start Hunting!

Translated by