如何绘制概率密度函数?

时间:2014-10-23 12:39:07

标签: matlab

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

2 个答案:

答案 0 :(得分:3)

我认为你想从你的数据估计概率密度函数。这是直方图,为此您使用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)

enter image description here

答案 1 :(得分:0)

如果您碰巧知道自己的发行版(例如Gaussian),可以这样做:

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

你可以得到这个,

enter image description here

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

相关问题