MATLAB histfit - 从数据中获取PDF,ksdensity?

use*_*994 0 matlab plot probability histogram

我想用histfit从图中得到密度曲线的方程.

我看到使用ksdensity函数可以得到一个点向量.这是最好的方法吗?

mwe*_*ler 8

histfit(data);
Run Code Online (Sandbox Code Playgroud)

将数据绘制为直方图,并显示最佳拟合高斯的平滑曲线.

[mu, sigma] = normfit(data);
pd = fitdist(data,'normal');
Run Code Online (Sandbox Code Playgroud)

将给出同一组数据的平均值(μ)和标准偏差(sigma),histfit用它来生成拟合曲线.

如果你这样做,edit histfit你可以查看它,看到正常曲线的高度是通过等于正常曲线下面积和直方图中的面积找到,找到周围的代码

% Normalize the density to match the total area of the histogram
xd = get(hh,'Xdata');             % Gets the x-data of the bins.
rangex = max(xd(:)) - min(xd(:)); % Finds the range of this data.
binwidth = rangex/nbins;          % Finds the width of each bin.
area = n * binwidth;
y = area * pdf(pd,x);
Run Code Online (Sandbox Code Playgroud)

有关进行缩放的那部分的更多提示.