How to extract coefficients from from curve fitting tool?

조회 수: 142 (최근 30일)
Benjamin
Benjamin 2020년 12월 10일
댓글: sebastian ruiz 2021년 12월 20일
Hello everyone,
I used Curve Fitting Tool in MATLAB and fitted a curve to some data points. Then generate the code and used it as a function as a part of my program. However, when the results show up, they are not stored in a cell or struct to be used later in the program. I am especifically refering to the model fit coefficients which is the output of the curve fitting function.
Does anybody know a way to extract the model fit coefficients.
Here I attached the program. By running the program the model fit (coefficients a and i) will be shown (as picture bellow), but not stored/saved in the workspace.
I appreciate your responses in advance
  댓글 수: 1
sebastian ruiz
sebastian ruiz 2021년 12월 20일
Greetings,
In case it is still good for you.
The output from a cftool will be a *.sfit
so for example,
fit001.sfit % your output and you want the goodness RMSEs
then while on that folder,
for i = 1:length
fit001_rmse(:,i) = fit001.AllFitdevsAndConfigs{i,1}.Fitdev.Goodness.rmse;
end

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 12월 10일
편집: John D'Errico 2020년 12월 10일
Simply enough. In fact, they ARE stored in the workspace. They are just not returned as separate variables. And that is a good thing. Extracting them is trivial though.
x = rand(10,1);
y = randn(10,1);
g1 = fit(x,y,'power1')
g1 =
General model Power1: g1(x) = a*x^b Coefficients (with 95% confidence bounds): a = -0.1631 (-0.6644, 0.3382) b = -0.4213 (-2.33, 1.487)
g1.a
ans = -0.1631
g1.b
ans = -0.4213
Or, if you wish to extract them as a vector of coefficients, just do
format long g
coeffvalues(g1)
ans = 1×2
-0.163113290762181 -0.421325379677972

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by