Whats wrong with this simpleGaussian Fit?

3 visualizaciones (últimos 30 días)
Jason
Jason el 8 de Nov. de 2015
Comentada: Jason el 10 de Nov. de 2015
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 comentarios
Jason
Jason el 9 de Nov. de 2015
Editada: Jason el 9 de Nov. de 2015
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 el 9 de Nov. de 2015
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(:))]);

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 9 de Nov. de 2015
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 comentarios
the cyclist
the cyclist el 10 de Nov. de 2015
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 el 10 de Nov. de 2015
Im sorry. It comes up with:
C:\Program Files\MATLAB\R2014b\toolbox\curvefit\curvefit\fit.m

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by