Question regarding the calling of cfit coefficients
조회 수: 3 (최근 30일)
이전 댓글 표시
I have used the 'fit' function to apply a power2 curve fit to some data. The cfit object is called fitobject. Shown below:
fitobject = fit(xdata, ydata, 'power2')
As a result I get three coefficients in the form y = ax^b + c.
I know the correct way to call the coefficients in a script is:
a = fitobject.a; b = fitobject.b; c = fitobject.c;
But if I call the following:
a = fitobject(1); b = fitobject(2); c = fitobject(3);
I get slightly different values of the coefficients. Could someone please explain where the values above come from, and thus why they differ. E.g why fitobject.a is not equal to fitobject(1) etc?
I have been scouring the internet and cannot find an explanation. I suspect it's something to do with the confidence bounds?
Many thanks!
댓글 수: 0
채택된 답변
Steven Lord
2023년 11월 28일
The way you gave, asking for the a, b, and c properties of the cfit object named fitobject, is one way to get the coefficients. This documentation page lists another: use the coeffvalues function. You'd probably also want to call the coeffnames function as well.
The second syntax you gave does not extract any coefficients at all. It evaluates the fit for x = 1, x = 2, and x = 3 respectively. Adapting the example on that documentation page:
load census
curvefit = fit(cdate,pop,'poly3','normalize','on')
Let's get one of the coefficients.
curvefit.p1
Let's get all the coefficients and display them as a table.
N = coeffnames(curvefit)
V = coeffvalues(curvefit)
results = table(N, V.', 'VariableNames', ["Coefficient names", "Coefficient values"])
What's the value of the fitted curve for the year 1925?
pop1925 = curvefit(1925)
Does this look right compared to the fitted curve and the data?
plot(curvefit)
hold on
plot(cdate, pop, 'ko', 1925, pop1925, 'bd')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
