Retrieve curve fit coefficients

7 次查看(过去 30 天)
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.

回答(2 个)

Steven Lord
Steven Lord 2021-9-15
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
Robert Demyanovich 2021-9-15
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.
  1 个评论
Steven Lord
Steven Lord 2021-9-16
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by