Draw a line throw a set of point

5 ビュー (過去 30 日間)
valerio auricchio
valerio auricchio 2020 年 11 月 3 日
回答済み: Image Analyst 2020 年 11 月 3 日
Hi i have a set of poin in an immage and i want to draw a line that is madiated by the positition of the points. I want something like this:
  1 件のコメント
Sean Doherty
Sean Doherty 2020 年 11 月 3 日
you could use polyfit()
this example is from polyfit help:
% Fit a polynomial p of degree 1 to the (x,y) data:
x = 1:50;
y = -0.3*x + 2*randn(1,50);
p = polyfit(x,y,1);
% Evaluate the fitted polynomial p and plot:
f = polyval(p,x);
plot(x,y,'o',x,f,'-')
legend('data','linear fit')

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

採用された回答

Image Analyst
Image Analyst 2020 年 11 月 3 日
Looks like he has a solution in his duplicate question: Click here for it

その他の回答 (1 件)

Rik
Rik 2020 年 11 月 3 日
For this code to work, you will need the attached fit_line function, and my point_to_line_distance, which you can find on the FEX or through the add-on manager.
x=[0.9, 3.2, 0.2, -0.0, -10.0, -1.2, 2.5, 2.9, 15.5, 4.3, -3.5, -3.6, -1.7, 0.5, -1.5, 12.0, ...
4.6, 6.4, -0.5, -1.1, -4.7, -0.2, -1.5, -3.5, -3.6, -0.1, -2.6, -11.5, 0.3, -0.2, 0.1, ...
-3.7, -0.1, 3.9, 11.4, -11.3, 1.4, -2.1, 8.7, -7.4, 1.4, -6.1, 2.6, 0.3, 1.2, 4.9, -1.0];
y=[5.0, -1.8, 2.3, 4.8, 1.4, 3.2, 3.7, 5.3, 4.3, 5.2, 2.6, 1.8, -4.3, 3.0, -0.5, 3.2, 5.0, ...
0.3, 6.2, -4.7, -3.3, 0.8, -0.4, 1.3, -6.0, 4.1, 1.6, 1.1, 3.8, -1.6, 1.1, 2.9, -0.7, ...
0.4, 10.7, -3.0, -0.8, 4.3, 3.3, -0.8, 5.8, 2.9, 1.9, 1.4, 6.2, 5.2, 1.6];
plot(x,y,'+r')
x_bounds=xlim;
p=fit_line(x,y);
hold on,plot(x_bounds,polyval(p ,x_bounds),'r');hold off
  2 件のコメント
valerio auricchio
valerio auricchio 2020 年 11 月 3 日
What are the point_to_line? And how can i import the function?
Rik
Rik 2020 年 11 月 3 日
Have you clicked the link? That would probably help...

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

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by