Help with basic fitting

4 ビュー (過去 30 日間)
aurc89
aurc89 2014 年 2 月 23 日
コメント済み: Image Analyst 2018 年 9 月 25 日
Hello,I would like to fit a curve with a line and retrieve slope and intercept of this linear fit. Let x and y be the vectors which define the curve, which is already similar to a line; I plot x vs y, then from the plot window I select Tools --> Basic fitting --> Linear fit, then I press 'Show equation' so that from the expression y=mx + q I retrieve both the slope m and the intercept q. The problem is that I want to obtain immediatly m and q from the Matlab code, without doing it manually as discussed above. How can I do this ? Thanks

採用された回答

Mischa Kim
Mischa Kim 2014 年 2 月 23 日
編集済み: Mischa Kim 2014 年 2 月 23 日
Try
[p,S] = polyfit(x,y,1)
The two elements of p are the coefficients m and q you are looking for.
  2 件のコメント
Andrea Gómez Montoya
Andrea Gómez Montoya 2018 年 9 月 25 日
What is S on the answer?
Image Analyst
Image Analyst 2018 年 9 月 25 日
It's explained in the help for polyfit().

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 2 月 23 日
for what it's worth, I've attached a demo of polyfit.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by