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.
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
Robert Demyanovich
2021년 9월 15일
댓글 수: 1
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 Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!