random normal distributed numbers

14 vues (au cours des 30 derniers jours)
Andreas
Andreas le 6 Juil 2012
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 ;)

Réponses (3)

Andrei Bobrov
Andrei Bobrov le 6 Juil 2012
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 le 6 Juil 2012
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 commentaire
AC
AC le 6 Juil 2012
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...)

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 6 Juil 2012
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