how to set nlinfit parameters ?J
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2017년 4월 22일
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
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!