I want to fit a cross-sectional image of a laser beam with a Gaussian function. And I'm thinking of using "nlinfit" to output the parameter covariance matrix. The image size is 1024 x 1344 pixels. The following process was performed, but fitting was not possible.
process
I=double(cdata)  % cdata is an array of image intensity distributions(1024×1344)
[h,w]=size(I);[X,Y]=meshgrid(1:w,1:h)
X=X(:);Y=Y(:);Z=I (:)
modelfun=@(b,X,Y)(b(1)+b(2)*exp((-1/2*(1-b(3)^2))*(((X-b(4))/b(5)).^2+((Y-b(6))/b(7)).^2-2*b(3)*(X-b(4)).*(Y-b(6))/(b(5)*b(7)))))
beta0=[15;150;0;600;90;570;85]
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit([X,Y],Z,modelfun,beta0)
When I performed the above process, I got an error if the number of arguments was incorrect.
Can you tell me the right way?

 채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 21일

0 개 추천

Your modelfun expects 3 parameters, but nlinfit requires a function that expects two parameters
You should probably use
modelfun=@(b,XY)(b(1)+b(2)*exp((-1/2*(1-b(3)^2))*(((XY(:,1)-b(4))/b(5)).^2+((XY(:,2)-b(6))/b(7)).^2-2*b(3)*(XY(:,1)-b(4)).*(XY(:,2)-b(6))/(b(5)*b(7)))))

댓글 수: 1

涼吾 神田
涼吾 神田 2021년 6월 21일
Thanks for your answer.
I was able to fit when I typed "XY=[X Y]" and the code you written.
Thank you very much for your prompt response!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 6월 21일

댓글:

2021년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by