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