Retrieve curve fit coefficients

조회 수: 3 (최근 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 CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by