【问题标题】:How to plot probability density function? [closed]如何绘制概率密度函数? [关闭]
【发布时间】:2014-10-23 12:39:06
【问题描述】:

我想为大约 7500 个显示峰值地面加速度 (PGA) 的数据绘制概率密度函数。对此的 MATLAB 代码是什么?谢谢。

【问题讨论】:

  • 嘿!让我为您搜索一下:“概率密度函数 Matlab”:mathworks.co.uk/help/stats/pdf.html。然后使用 plot()。
  • 我认为 OP 想要 hist,而不是 pdf
  • @LuisMendo OP 与命名法有点混淆! :P 好点。
  • @mohamad:欢迎来到 Stack Overflow。一般来说,这里不欢迎“给我代码”的问题。你会想先做一些你自己的研究和实验,然后告诉我们你做了什么。我们在这里为您提供指导,但您应该假设您需要自己编写代码。
  • 感谢 jasonmc92 的建议。

标签: matlab


【解决方案1】:

我认为您想估计您的数据中的概率密度函数。这是一个直方图,为此您可以使用hist 函数:

data = randn(1,7500); %// example data
n = 21; %// number of bins
[y, x] = hist(data, n);
y = y/(x(2)-x(1))/numel(data); %// normalize so that total area is 1
plot(x, y)
%// To check that area is approximately 1, compute the integral: trapz(x, y)

【讨论】:

    【解决方案2】:

    如果你碰巧知道你的分布(例如高斯分布),你可以这样做:

    data = randn(1,7500);
    [mu sigma] = normfit(data);
    X = mu - 10 : .1 : mu + 10;
    Y = normpdf(X,mu,sigma);
    plot(X,Y);
    

    你可以得到这个,

    但是,如果您的数据不是高斯数据,您可以使用其他拟合函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      相关资源
      最近更新 更多