MATLAB: Output of surface fit function to workspace

surface fitting output

Hi! By using the GUI of cftool or by using the command "fit( [x, y], z, 'poly22')" I can fit x,y and z-data to get a function like
f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2
with:
p00 = 0.0005919 (0.0005906, 0.0005932)
p10 = -0.03397 (-0.03401, -0.03393)
… and so on
Is there a way to get an output of the pxx-values to workspace?
I mean like when you fit 2D-data with "[p,S]=polyfit(x,z,2)" these values are written to p.
Thaks a lot 🙂

Best Answer

Two ways:
Method1, interactively:
Go to the "fit" tab and "Save to workspace". This will save the fittedmodel and you can get the coefficients by saying:
fittedmodel.pxx
Method2, programatically.
Go to file -> generate code to generate a function that will return the fitted model. Then call this function like any other, retreive the fittedmodel and get the coefficients the same way as a above
[fittedmodel,gof] = createFit(x,y,z);
fittedmodel.p01