nlinfit for a function of 2 variables

2 ビュー (過去 30 日間)
Roy Elbaz
Roy Elbaz 2017 年 8 月 29 日
回答済み: Star Strider 2017 年 8 月 29 日
Hey,
I want to get a Gaussian git for my data using Matlab. However, I'm expecting a 2D Gaussian - Z(x,y)=A*exp(-(x^2+y^2)/2σ^2) Is there a way of using nlinfit for this?
I saw another question here about nlinfit for a 2 variables function, however in that function they weren't coordinates. I need all the combinations of X and Y in order to make the fit.
loc=[XC YC];
gaussian = @(param,x) param(1)*exp( -((x(:,1)-param(2)).^2+(x(:,2)-param(3)).^2+)./(2*param(4).^2) ) + param(5);
params=zeros(1,5);
params(1)=A*maxVal;
params(2)=maxXpos;
params(3)=maxYpos;
params(4)=estW;
params(5)=nPixInf(1,1);
paramsX = nlinfit( loc , nPixInf , gaussian , params );
XC and YC are just 2 one dimensional arrays that goes from 1 to the size of that dimension. nPixInf is a 2 dimensional matrix which suppose to look like a Gaussian.
Can I use nlinfit for this?
Thanks!

回答 (1 件)

Star Strider
Star Strider 2017 年 8 月 29 日
It looks to me that you have coded your ‘gaussian’ function correctly. (I’ve used this approach successfully with nlinfit.)
Are you having problems with it?

カテゴリ

Help Center および File ExchangeProbability Distributions and Hypothesis Tests についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by