How do I generate a random number with normal distribution

I want to generate a random matrix with normal distribution between -10 and 10. I cannot use randn() because it has no boundaries. Is there any other to generate such matrix??

 Respuesta aceptada

This is called a truncated distribution. While you are correct that it is no longer strictly a normal distribution (that extends to infinity to either side of the mean), you can nevertheless define it. The extended discussion is in the truncate (link) documentation section in Truncate a Probability Distribution (link).
For your Question, this would be:
pd = makedist('Normal')
t = truncate(pd,-10,10)
r = random(t,10000,1);
Experiment to get the result you want.

2 comentarios

Thanks. It really worked. However I found out that the mean and standard deviation has effects to make me get close to the boundary -10 and 10. So i made a simple loop to check which best fits.
for i = 1:9
pd = makedist('Normal',0,i);
t = truncate(pd,-10,10);
r = random(t,10000,1);
subplot(3,3,i)
hist(r,100)
max(r)
min(r)
end
In here, I set my mean to 0 and my standard deviation is i. When i is >= 3, it fits perfectly for what I am looking for as my max and min are more close to my boundaries.
Thanks again for the help
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Mzo. de 2019

Comentada:

el 30 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by