ezfit using a function

7 次查看(过去 30 天)
aneps
aneps 2022-7-8
I use ezfit to fit a gaussian in my data. It is straight forward as it is in the ezfit examples:
f1 = ezfit(x,counts,'gauss');
showfit(f1)
I want to fit my own function. So before doing that, I attempted using the equation of gaussian, exaclty the same equation in the ezfit documentation to fit the data ( http://www.fast.u-psud.fr/ezyfit/html/ezfit.html ). I am doing this to check if I am doing any mistakes. I did as follows
f1 = ezfit(x,counts,'a*exp(-(x-x0)^2/(2*s^2))');
showfit(f1)
This time it doesn't fit! Could you please tell me what is wrong in it?
  2 个评论
Natalia Demidova
Natalia Demidova 2022-7-12
Hi,
Notice in the ezfit documentation the way functions are specified are with syntax of "y=" as in a usual function. Thus it should look like:
f1 = ezfit(x,counts,'y = a*exp(-(x-x0)^2/(2*s^2))');
Further for your own function you can specify specific guesses for parameters (such as a and s here). The first guesses for the function (ex. a=1 and s=2) to try would be after semicolon in the same string and look like:
f1 = ezfit(x,counts,'y = a*exp(-(x-x0)^2/(2*s^2)); a=1; s=2');
Have fun :)
aneps
aneps 2022-7-13
Still it doesn't fit! I used f1 = ezfit(x,counts,'y = a*exp(-(x-x0)^2/(2*s^2))');, it doesn;t work. But if I use f1 = ezfit(x,counts,'gauss'); it do the job! Don't understand what cause this difference. Data attached.. Here, first I plot the histogram of column 9. Then I do the curve fit on the histogram.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by