How to generate random numbers in a Gaussian distribution?
310 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Given A = 1 and B = 5, and knowing that the mean is 2.5 and the standard deviation is 1, I want to generate 1000 random points between A and B using a normal (Gaussian) distribution. I am unsure how to do this in MATLAB efficienctly.
6 commentaires
Walter Roberson
le 7 Fév 2023
values = mean + randn(1000,1) * sigma;
The repmat() is valid, but slower than needed for this purpose.
Réponse acceptée
Swaraj
le 8 Fév 2023
You can use the randn function in MATLAB.
You can follow the following steps:
- Generate Random Numbers from a standard normal distribution.
- Scale and shift them to match the desired Mean and Standard Deviation.
Please go through the code below:
A = 1;
B = 5;
std = 1;
mean = 2.5;
step1Result = mean + std * randn(1000,1);
step2Result = min(max(step1Result,A),B);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Random Number Generation 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!