Normal random number generation
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to generate some random numbers which should lie between 0 and 1. Also those values should follow nornal ditribution. Is there any readymade function for it, in MATLAB?
1 commentaire
Dyuman Joshi
le 22 Sep 2022
Modifié(e) : Dyuman Joshi
le 22 Sep 2022
You can normalize the data in between 0 to 1, though I am not sure if it will still follow normal distribution or not.
y=randn(1,7)
y=(y-min(y))/(max(y)-min(y))
I also recommend you check out these comments -
Réponses (2)
Torsten
le 22 Sep 2022
Modifié(e) : Torsten
le 22 Sep 2022
pd = makedist('Normal');
t = truncate(pd,0,1);
r = random(t,1e6,1);
figure(1)
histogram(r,100)
Or directly:
r = -sqrt(2)*erfinv(rand(1e6,1)*erf(-1/sqrt(2)));
figure(2)
histogram(r,100)
Of course, the random numbers are not normally distributed in the usual sense.
1 commentaire
Dyuman Joshi
le 22 Sep 2022
Quite a neat function.
However, OP might not have access to Stats and ML toolboox.
Bruno Luong
le 22 Sep 2022
Here is an alternatve without stats tbx
X=TruncatedGaussian(-1,[0 1],[1, 1e6]);
histogram(X)
0 commentaires
Voir également
Catégories
En savoir plus sur Descriptive Statistics and Visualization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!