I want to add a line of best fit to my plot using the polyfit function.

17 ビュー (過去 30 日間)
Norman Vyne
Norman Vyne 2019 年 8 月 15 日
コメント済み: Jon 2019 年 8 月 16 日
%Plot graph 1
figure(2); clf
plot(xL(A),anglex,'ko');
  2 件のコメント
darova
darova 2019 年 8 月 15 日
Can you show something more?
John D'Errico
John D'Errico 2019 年 8 月 15 日
Note that the simplest way to add that line of best fit is to plot your data, then use the basic fitting tools menu item on the plot itself.

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

採用された回答

Jon
Jon 2019 年 8 月 15 日
編集済み: Jon 2019 年 8 月 15 日
You can do something like this
p = polyfit(xL(A),anglex,1);
anglexFit = polyval(p,xL(A));
plot(xL(A),anglex,'ko',xL(A),anglexFit)
I'm assuming your variable A, is a vector of indices that give the elements of xL that you want plotted and fit.
Also you can enter the command doc polyfit on the command line and it will bring up the documentation for polyfit, which has some nice examples of plotting best fit lines.

その他の回答 (1 件)

Image Analyst
Image Analyst 2019 年 8 月 16 日
See attached demo of polyfit where I fit a line and a dubic to some data.
Attach your data and show a screenshot of it plotted if you want anymore help.

カテゴリ

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