How can I plot a straight line from a curve?

36 ビュー (過去 30 日間)
Jahan N
Jahan N 2021 年 9 月 1 日
コメント済み: Jahan N 2021 年 9 月 1 日
I want to draw a straight line across (0,0) point from the given data point.
My code with data point:
x =3:1:18;
y = [.06 .09 .115 .1288 .146 .17 .19 .224 .267 .3058 .336 .378 .491 .495 .518 .509];
plot(x,y,'-o')
grid on
hold on
Figure:
But , I want to draw a straight line.

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 9 月 1 日
To plot a line between a point [x_i,y_i] and [0,0] simply do this:
ph0p = plot([0,x_i],[0,y_i]);
Then you can decorate the line using the plot-handle ph0p and the set function.
For example from the fifth point in your curve this would become:
i_xy = 5;
ph0p = plot([0,x(i_xy)],[0,y(i_xy)]);
HTH

その他の回答 (1 件)

Matt J
Matt J 2021 年 9 月 1 日
Maybe this is what you want?
x =3:1:18;
y = [.06 .09 .115 .1288 .146 .17 .19 .224 .267 .3058 .336 .378 .491 .495 .518 .509];
p=polyfit(x,y,1);
plot(x,y,'o', x,polyval(p,x))
grid on
hold on
  1 件のコメント
Jahan N
Jahan N 2021 年 9 月 1 日
Thanks for your effort.Your answer is also useful.

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

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by