how to plot polyfit same plot as scatter

114 ビュー (過去 30 日間)
Ous Chkiri
Ous Chkiri 2021 年 4 月 17 日
回答済み: Cris LaPierre 2021 年 4 月 17 日
figure (1)
scatter(Alpha(X_new),CD_new,'linewidth',0.0001);
p=polyfit(Alpha(X_new),CD_new,1);
xlabel('Alpha');
ylabel('CD');

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 4 月 17 日
Look at some of the examples on the polyval documentation page.
Polyfit just returns the coefficient values. If you want to plot it, you need to evaluate your polynomial, and then plot the resulting values using plot.
x = linspace(0,4*pi,10);
y = sin(x);
p = polyfit(x,y,7);
% evaluate polynomial
x1 = linspace(0,4*pi);
y1 = polyval(p,x1);
% plot
scatter(x,y)
hold on
plot(x1,y1)
hold off
legend('Data','Polyfit')

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by