Using lsqcurvefit with constant parameters

Hi, I am trying to use lsqcurvefit to fit data to an interference function that I created. The problem is that some of the parameters in the function should remain constant through the fitting process (ie. the wavelength of the laser does not change etc...). I have seen some other stabs at this but none that were thorough and actually worked when I ran them. Here is some of my code so you know what I am talking about:
initials = [Aref,Aprobe,w0,z,lambda,phi,x0,y0];
fitfunc = @(initials,x) InterferePhase1(initials,X2);
fitparams = lsqcurvefit(fitfunc,initials, X2 ,imageArray,[], []);
Ideally, I should be able to run this fit and have my initial values for lambda, x0, and y0 stay the same after lsqcurvefit runs.
Let me know if you need any additional information!
Thanks for all your help!

 채택된 답변

Matt J
Matt J 2014년 7월 24일
편집: Matt J 2014년 7월 24일

0 개 추천

initials = [Aref,Aprobe,w0,z,phi];
fitfunc = @(p,pdata) InterferePhase1([p(1:4),lambda,p(5),x0,y0],pdata);
fitparams = lsqcurvefit(fitfunc,initials, X2 ,imageArray);

댓글 수: 3

Chris
Chris 2014년 7월 24일
Thanks for your help. I run into problems though with the number of elements because InterferePhase1 requires 8 inputs and now the initials vector has only 5 inputs. It seems to be close though so i'll play around with it.
Matt J
Matt J 2014년 7월 24일
As you can see, though, my proposed fitfunc does pass 8 inputs to InterferePhase1 (that was the whole point). It embeds the 5 unknowns in an 8-vector which includes lambda, x0, and y0.
Chris
Chris 2014년 7월 25일
Ya I got it working and understand what you're doing now.
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기

질문:

2014년 7월 24일

댓글:

2014년 7월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by