简体   繁体   中英

normalize 2 histogram and plot

I'm new in matlab and i tried to normalize two normal distributions according to How to normalize a histogram in MATLAB? , but i couldn't. Can someone tell me how to normalize the two normal distribution below:

[f,x]=hist(normrnd(25,2.5),50);%# create histogram from a normal distribution.
g=1/sqrt(2*pi)*exp(-0.5*x.^2);%# pdf of the normal distribution

figure(1)
bar(x,f/trapz(x,f));hold on
plot(x,g,'r');hold off

Thanks!

Two suggestions:

  1. Use randn instead of normrnd.
  2. Increase the number of numbers you are trying to generate.

Code:

[f,x]=hist(randn(10000,2.5),50);%# create histogram from a normal distribution.
g=1/sqrt(2*pi)*exp(-0.5*x.^2);%# pdf of the normal distribution

figure(1)
bar(x,f/trapz(x,f));hold on
plot(x,g,'r');hold off

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM