How to know the equation of a curve fitted to histogram

29 次查看(过去 30 天)
Hi matlab users,
I have plotted a histogram in matlab and then used
histfit(pair_dist,9,'kernel')
command to fit a curve to the histogram. Now i need to find the equation of curve fitted with this histogram. Can anyone suggest a way to find out this?

采纳的回答

Adam Danz
Adam Danz 2022-1-13
编辑:Adam Danz 2022-1-13
The output of histfit is a vector of handles, one of which is a line object containing the x/y values for the curve. You could fit those line values to a gaussian function to get the fit parameters. Update: if you're using "kernel", that's a nonparametric kernel-smoothing distribution where the density is evaluated at 100 equally spaced points that cover the range of the data so it has no parameters to fit.
Alternatively, you could use fitdist instead of histfit to fit the distribution and return the fit parameters. These two methods are compared in this answer.
y = randn(1,1000)+6.2*9.8;
h = histfit(y);
lineobj = findobj(h,'type','line');
gx = lineobj.XData;
gy = lineobj.YData;
f = fit(lineobj.XData',lineobj.YData','gauss1')
f =
General model Gauss1: f(x) = a1*exp(-((x-b1)/c1)^2) Coefficients (with 95% confidence bounds): a1 = 93.96 (93.96, 93.96) b1 = 60.79 (60.79, 60.79) c1 = 1.459 (1.459, 1.459)
% Now plot the fitted line again see that it's the same
hold on
plot(f,'g-')

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by