简体   繁体   English

归一化2直方图并绘图

[英]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? 我是Matlab的新手,我尝试根据如何在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. 使用randn代替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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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