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 Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by