标准化2直方图和绘图

时间:2014-10-26 23:26:39

标签: matlab graph plot normal-distribution

我是matlab的新手,我试图根据How to normalize a histogram in MATLAB?规范化两个正态分布,但我不能。有人可以告诉我如何规范下面的两个正态分布:

[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

谢谢!

1 个答案:

答案 0 :(得分:1)

两个建议:

  1. 使用randn代替normrnd。
  2. 增加您尝试生成的数字。
  3. 代码:

    [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