필터 지우기
필터 지우기

how to set nlinfit parameters ?J

조회 수: 1 (최근 30일)
Anna Levy
Anna Levy 2017년 4월 21일
댓글: Star Strider 2017년 4월 22일
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 !!

채택된 답변

Star Strider
Star Strider 2017년 4월 22일
I’m in a context here that is very much less than clear.
The Gaussian function is defined as:
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.

추가 답변 (1개)

Anna Levy
Anna Levy 2017년 4월 22일
Thanks for your answer. I was trying to find a way to use nlinfit in a different way. But anyway, I found out my solution.
Sorry my question was really not clear.

카테고리

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