How do I sample a random value from a normal distribution
Afficher commentaires plus anciens
I want to sample a value from a normal distribution and I wrote down this codes. Can someone please look at it and hint me if it is appropriate. I am Matlab basic user.
r=rand;
ci_l=find(cumu<=r,1,'last');
ci_h=find(cumu>=r,1,'first');
if abs(cumu(ci_l)-r)<=abs(cumu(ci_h)-r)
ci=ci_l;
else
ci=ci_h;
end
cmuO=getCDF(pdfY);
cmuO=cmuO/max(cmuO);
[~,idx]=min(abs(cmuO-cumu(ci)));
newVal=pdfX(idx);
7 commentaires
Walter Roberson
le 17 Avr 2019
??
normrnd() perhaps ?
Gumps
le 17 Avr 2019
Walter Roberson
le 17 Avr 2019
I do not understand the point of any of that.
Is cumu a previously initialized vector of randn() values? Sorted output of randn() in particular?
I do not understand what you think you are calculating.
Gumps
le 17 Avr 2019
Walter Roberson
le 17 Avr 2019
Is Cumu a distribution created with makedist() https://www.mathworks.com/help/stats/makedist.html or is it a vector of values ? If it is a vector, is the vector sorted in increasing order?
Gumps
le 17 Avr 2019
Walter Roberson
le 18 Avr 2019
Is the "YES" intended to mean that Yes, it is a vector sorted in increasing order?
Réponses (1)
James Tursa
le 17 Avr 2019
doc randn
Catégories
En savoir plus sur Uniform Distribution (Continuous) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!