【问题标题】:MATLAB Adding Gaussian fit to histogramMATLAB将高斯拟合添加到直方图
【发布时间】:2013-11-19 16:11:59
【问题描述】:

我正在尝试将高斯拟合添加到 MATLAB 中的直方图,但我不知道如何仅将拟合应用于一个特定的峰值。

http://postimg.org/image/phms61rdh/ 第一个情节

http://postimg.org/image/sindrn8er/第二个情节

我还发布了我一直在使用的部分代码:

    data_Rb = (importdata('path\name.txt'));
    counts_Rb = data_Rb.data(:,3);
    figure
    hist(counts_Rb, nbins);
    xlim([0 120]);
    title('Rubidium');
    histfit(counts_Rb,1000);

    pd=fitdist(counts_Rb(:),'normal')
    x=0:0.001:120;  
    PDF=pdf(pd,x); %PDF is a vector of y values: it's our fit
    PDF=PDF/max(PDF); %nor
    y=ylim;
    PDF=PDF*y(2);
    hold on
    plot(x,PDF,'r-','LineWidth',2);
    hold off

这两个块给了我两个不同的高斯,如第一张图片所示。我不明白为什么它们如此糟糕地拟合数据:是因为 RHS 的尾巴吗?

在第二个图中,我只需要对最后一个峰值应用高斯拟合。我该怎么做?

最后,应用拟合后,拟合结果输出到屏幕上。是否有将它们保存到数组中以供以后使用的功能?

提前致谢!

【问题讨论】:

标签: matlab histogram curve-fitting gaussian


【解决方案1】:

关于您的最后一个问题,请参阅How can I access the fitted distribution parameters from the HISTFIT function in Statistiics Toolbox ?

复制 HISTFIT 可以解决此问题 函数并修改代码以传递“pd”变量。单程 这样做是改变代码第一行的“h”输出 到“varargout”并将以下内容添加到文件末尾:

h = [hh; hh1];
argout={h,pd};
if nargout > length(argout)
error('Too many output arguments.');
end
[varargout{1:nargout}]=argout{1:nargout};

【讨论】:

    猜你喜欢
    • 2015-08-11
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 2014-11-12
    • 2013-01-08
    • 1970-01-01
    • 2018-02-17
    • 2022-01-06
    相关资源
    最近更新 更多