how to set nlinfit parameters ?J
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anna Levy
le 21 Avr 2017
Commenté : Star Strider
le 22 Avr 2017
Hello
I would need some help for fitting my data. Let's assume that I want to fit data registred in the matrix "spe":
x=spe(N,1)
y=spe(N,2)
and that it should be fitted by a Gaussian function
I have defined the matlab function for the Gaussian :
function fun = gauss(b1,b2,b3,x)
fun = b3 * (1/(b1*sqrt(2*pi))) * exp(-(x-b2).^2/(2*(b1).^2));
end
and then, I want to use this function to fit my spe data using this expression in my main program using the nlinfit function.
As far as I understood, I have to create a function handle, which, by the way I am not understanding exactly what it is, in order to use nlinfit :
I tried :
mdl = @gauss
b0 = [1 1480 500];
b = nlinfit(spe(:,1), spe(:,2), mdlgausstest,b0);
but it is returning some error message.
Could you help me? Thank you very much !!
0 commentaires
Réponse acceptée
Star Strider
le 22 Avr 2017
I’m in a context here that is very much less than clear.
Gauss = @(a,b,c,x) a*exp(-((x-b)/(2*c)).^2);
or in terms that the nlinfit function will understand:
Gfcn = @(p,x) p(1).*exp(-((x-p(2))./(2*p(3))).^2);
Use the ‘Gfcn’ function as your objective function with nlinfit and all should be well.
Your ‘mdl’ function makes absolutely no sense to me, so I won’t essay to correct it.
So just use ‘Gfcn’, and — with the correct initial parameter estimates vector — you should have no problems fitting it to your data, if they are truly described by a Gaussian function.
Note — I do not have your data to test this with, so I am listing it as UNTESTED CODE. It should work.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!