フィルターのクリア

FIT function output structure

25 ビュー (過去 30 日間)
Bob Adams
Bob Adams 2015 年 6 月 6 日
コメント済み: Yanis Arencibia 2023 年 6 月 10 日
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 Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by