FIT function output structure

16 次查看(过去 30 天)
Bob Adams
Bob Adams 2015-6-6
I am using the fit function for the first time, and I notice that all the examples pass the returned object into the PLOT function. However I am not interested in plotting the results, but rather I need to get the fitted curve into an array. I don't see any documentation that show how to do this.

回答(1 个)

Sreeja Banerjee
Sreeja Banerjee 2015-6-8
Hi Bob,
The function FIT returns a cfit object for curves or a sfit object for surfaces. You can learn more about the objects in the documentation:
In short, the CFIT object will return the model formula and the coefficients. For example,
>> load census;
>> f=fit(cdate,pop,'poly2')
f =
Linear model Poly2:
f(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = 0.006541 (0.006124, 0.006958)
p2 = -23.51 (-25.09, -21.93)
p3 = 2.113e+04 (1.964e+04, 2.262e+04)
I assume from your question that you want to extract the coefficients into an array. You can do that by using the following syntax:
>> coeff = coeffvalues(f)
coeff =
1.0e+04 *
0.0000 -0.0024 2.1130
You will need use the COEFFVALUES function, details of which you can find in the following link: http://www.mathworks.com/help/curvefit/coeffvalues.html
If you also need to extract the formula and the coefficient names then you may use the following functions:
>> formula(f)
ans =
p1*x^2 + p2*x + p3
>> coeffnames(f)
ans =
'p1'
'p2'
'p3'
  1 个评论
Yanis Arencibia
Yanis Arencibia 2023-6-10
If I may add to Sreeja's answer, a fast and nice way to access the coefficients is as follows:
>> load census;
>> f=fit(cdate,pop,'poly2');
Now you can call (or reuse in another function) the coeffs just typing:
>> f.p1
>> f.p2
>> f.p3
I hope this helps.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by