Retrieve curve fit coefficients

7 ビュー (過去 30 日間)
Robert Demyanovich
Robert Demyanovich 2021 年 9 月 15 日
コメント済み: Steven Lord 2021 年 9 月 16 日
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 Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by