フィルターのクリア

how to make linear fit

14 ビュー (過去 30 日間)
ahmad Saad
ahmad Saad 2023 年 10 月 22 日
コメント済み: William Rose 2023 年 10 月 22 日
Hi;
How to make a plot similar to the attached figure ??

採用された回答

William Rose
William Rose 2023 年 10 月 22 日
There are a number of ways you could do it. here is one example:
x=0:100;
y=2*x+20+10*randn(1,101);
p=polyfit(x,y,1);
% Compute fitted values
yfit=polyval(p,x);
% Plot results
plot(x,y,'b.',x,yfit,'-r')
Try it. Good luck.
  1 件のコメント
William Rose
William Rose 2023 年 10 月 22 日
If you also want the RMSE and Pearson correlation, do the same code as before plus a few lines:
x=0:100;
y=2*x+20+10*randn(1,101);
p=polyfit(x,y,1);
rho=corr(x',y')
rho = 0.9876
% Compute fitted values
yfit=polyval(p,x);
rmse=sqrt(mean((yfit-y).^2))
rmse = 9.0371
% Plot results
plot(x,y,'b.',x,yfit,'-r')
And if you want to add the rho and rmse to the plot, do this:
hold on;
s1=sprintf('RMSE=%.2f',rmse);
text(10,200,s1);
s2=sprintf('rho=%.3f',rho);
text(60,200,s2)
text();
OK

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by