【问题标题】:Can someone show me how to plot Uniform distribution on matlab?有人可以告诉我如何在 matlab 上绘制均匀分布吗?
【发布时间】:2015-05-28 12:43:16
【问题描述】:

我已经有了这段代码,我从高斯分布中借用了一些代码并对其进行了修改。 如下

[f,x]=hist(rand(1000000,1),50);%# create histogram from a normal distribution.
g=1/sqrt(2*pi)*exp(-0.5*x.^2);%# pdf of the normal distribution
%#METHOD 2: DIVIDE BY AREA
figure(2)
bar(x,f/trapz(x,f));hold on
plot(x,1,'r');hold off .

现在有什么我可以改变它以使红线不分色或不分色吗? 让我知道 。 非常感谢!!

【问题讨论】:

    标签: matlab distribution uniform


    【解决方案1】:

    你希望红线是什么?如果你想要一条恒定的红线,你应该使用

    plot(x,ones(size(x)),'r-')
    

    如果你想根据均匀分布绘制这个,归一化为一,

    [f,x]=hist(rand(1000000,1),50);
    bar(x,f/trapz(x,f));hold on
    plot(x,ones(size(x)),'r-');
    hold off 
    

    其中除以函数的积分得到分布下的面积等于一。

    如果你想要直接的高斯分布,你应该从randn而不是rand获取随机数,例如

    [f,x]=hist(randn(1000000,1),50)
    bar(x,f/trapz(x,f))
    

    【讨论】:

    • 谢谢。我想要第一个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2011-07-16
    • 2011-11-30
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    相关资源
    最近更新 更多