# Retrieve curve fit coefficients

5 views (last 30 days)
Robert Demyanovich on 15 Sep 2021
Commented: Steven Lord on 16 Sep 2021
I am using a 4PL function written by someone and available from a MatLab search. I don't understand how to store the curve fitting coefficients that the function provides. Below I think is the relevant code:
%-----------------------------Fit the data---------------------------------
fo = fitoptions('method','NonlinearLeastSquares','Lower',L,'Upper',U);
set(fo,'Startpoint',st);
if all(we) % if y was a matrix use std as weights for fitting
set(fo,'Weights',we);
end
ft = fittype('D+(A-D)/(1+(x/C)^B)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'A', 'B', 'C', 'D'});
[cf,G] = fit(x,y,ft,fo);
This code prints the coefficients A, B, C and D but doesn't store them so I can use them for something else. How do I store the coefficients so that after the function executes the coefficients are availabe for use in the main code.

Steven Lord on 15 Sep 2021
What "something else" are you planning to do with this fit information? There are a number of post-processing operations you can perform on cfit objects (like the cf that you return from the fit function) that you may be able to use without reinventing the wheel.
If you do just need to extract the coefficients see the coeffvalues and coeffnames functions listed on the documentation page to which I linked above.
If your "something else" is to evaluate the fit, see the "Evaluate a Curve Fit" topic linked from that page.

Robert Demyanovich on 15 Sep 2021
I tried using coeffvalues, but all it does is store a bunch of text including the values that I want in a 1x1 something or other. I want to have the coefficients stored in a table so I can use the coefficients for calculation of the parameters that I need in the model simulation of my experimental data. I can't believe how difficult this is.
Steven Lord on 16 Sep 2021
Can you show what the variable cf on which you call coeffvalues looks like when you display it and what the output of the coeffvalues call looks like? There are some types of curves where the coefficients aren't so simple to represent as a simple vector.