Draw a line throw a set of point

조회 수: 8 (최근 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 CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by