2D data fitting - Surface
Show older comments
Dear all,
I wanted to adapt the post 2D data fitting - Surface that uses lsqcurvefit to fit data defined on a 2D grid and use instead nlinfit and fitnlm.
For nlinfit replacing the following
B = lsqcurvefit(surfit, [0.5 -0.5 -0.5], XY, z, [0 -10 -10], [1 10 10])
with
flatten = @(X) X(:);
Surfit = @(B,XY) flatten(surfit(B,XY));
B = nlinfit(XY,flatten(z),Surfit,[0.5 -0.5 -0.5],statset('Display','final'))
seems to works fine even though results differ slightly but I can't figure out how to do the same with fitnlm. I tried
flatten = @(X) X(:);
Surfit = @(B,XY) flatten(surfit(B,XY));
B = fitnlm(XY,flatten(z),Surfit,[0.5 -0.5 -0.5],'Options',statset('Display','final','Robust','On'))
but I get the following error
Error using classreg.regr.FitObject/assignData (line 140)
All predictor and response variables must be vectors or matrices.
Error in NonLinearModel.fit (line 1417)
model =
assignData(model,X,y,weights,[],model.Formula.VariableNames,exclude);
Error in fitnlm (line 99)
model = NonLinearModel.fit(X,varargin{:});
Error in fit2d (line 69)
B = fitnlm(XY,flatten(z),Surfit,[0.5 -0.5 -0.5],...
Any suggestion on how to proceed most welcome!
Many thanks, Patrick
1 Comment
Patrick
on 12 Oct 2018
Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!