首页 > 解决方案 > 如何在 Matlab 中将曲线拟合到直方图?

问题描述

我探索了关于上述主题的类似问题,但他们无法帮助我找到以下直方图的良好曲线。例如,在以下代码的输出中,曲线的峰值很高(它具有高峰度)。如何解决这个问题呢?

代码:

SumR = [1.02957968211466e+23,1.12316700832322e+16,1.01205904405943e+24,1.23183231736978e+22,1.71254955156886e+18,0,2.78888971554146e+16,1.06495767772703e+21,1.02761772773492e+24,2.56040885583339e+19,3.04201226469320e+21,1.12113264824989e+20,5.23573831147063e+18,1.95497792957160e+19,1.36150887360868e+19,4.41352571341253e+22];

h = histogram(SumR, 'FaceColor','g');  % SumR is a vector with dim 1x16.
numbins = h.NumBins; % In this example is 3.

 ...' figure out how to scale the pdf, to the area of the histogram.
[bincounts,binpos] = hist(SumR, numbins);
binwidth = binpos(2) - binpos(1);
histarea = binwidth*sum(bincounts);

...' kernel estimator.
[f,x,u] = ksdensity(SumR);
line(x, f*histarea, 'Color', 'g', 'LineWidth',2);

输出:

在此处输入图像描述

并且,考虑下面的图像,曲线的哪个峰值应该像红色曲线。

在此处输入图像描述

标签: matlabhistogramcurve-fitting

解决方案


推荐阅读