MATLAB: How to get fitting parameter in sftool.

fitting parameterssftool

I have three parameters as x, y, z.
I want to fit these parameters as z = a*x + b*y.
After I finish fitting at sftool. I generate M-file. By modify this M-file, I want to save fitting parameter a and b at work space.
How could I do this?

Best Answer

The generated code should look something like this:
%%Initialization.
% Convert all inputs to column vectors.
x = x(:);
y = y(:);
z = z(:);
%%Fit: 'untitled fit 1'.
ft = fittype( 'poly11' );
opts = fitoptions( ft );
opts.Weights = zeros(1,0);
[fitresult, gof] = fit( [x, y], z, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [x, y], z );
legend( h, 'untitled fit 1', 'z vs. x, y', 'Location', 'NorthEast' );
% Label axes
xlabel( 'x' );
ylabel( 'y' );
zlabel( 'z' );
grid on
And fitting parameters are stored in fitresult:
fitresult.p00
fitresult.p01
fitresult.p10
Related Question