Whats wrong with this simpleGaussian Fit?

3 次查看(过去 30 天)
Jason
Jason 2015-11-8
评论: Jason 2015-11-10
For some reason the fit doesn't fit!
%Gaussian Fit--------------------------------------------------------
gaussEqn = 'a*exp(-((x-b)/c).^2)+d'
f = fit(xdata',ydata',gaussEqn)
%Results of fit
coeffs=coeffvalues(f);
a=coeffs(1)
b=coeffs(2)
c=coeffs(3)
d=coeffs(4)
figure
plot(xdata',ydata','r.') %plot raw data
hold on;
%Increase resolution of x data
xdataFine=(linspace(xdata(1),xdata(end),30))
%plot high res fit
fitGaus = a*exp(-((xdataFine-b)/c).^2)+d
plot(fitGaus,'g-')
hold off.
  2 个评论
Jason
Jason 2015-11-9
编辑:Jason 2015-11-9
It seems the parameters fromt he fit are wrong. This is my data
and here are the results of the fit
f =
General model:
f(x) = a*exp(-((x-b)/c).^2)+d
Coefficients (with 95% confidence bounds):
a = 0.4218
b = 0.9157
c = 0.7922
d = 3351 (-646.9, 7349)
"b" should be close the 7 so I can't figure out whats going wrong with the fit, and then to plot the fit as well.
It fits fine in Mathcad.
Jason
Jason 2015-11-9
Ok, it seems like its not possible to do the fit without using start guesses:
f = fit(x,y,gaussEqn,'Normalize','off', 'StartPoint',[max(y(:))-min(y(:)),xValue,c,min(y(:))]);

请先登录,再进行评论。

回答(1 个)

the cyclist
the cyclist 2015-11-9
Those red circles look like they are the result of binning and counting the data (and making a histogram-style figure). Are those counts what you are putting into the fit? Most fitting routines in MATLAB expect the underlying data, not counts.
fit points to several functions in MATLAB, depending on context. Which function is it?
  3 个评论
the cyclist
the cyclist 2015-11-10
You misunderstood my last question. When you type
which fit
what MATLAB function comes up? (I'm trying to understand which function to look at to help you diagnose the issue.)
Jason
Jason 2015-11-10
Im sorry. It comes up with:
C:\Program Files\MATLAB\R2014b\toolbox\curvefit\curvefit\fit.m

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by