How to find which are the nearest points to the line segment?
3 views (last 30 days)
Show older comments
I have a vector X size 50x1 and a vector Y size 50x1. If i
plot(X, Y, 'r+')
then I get the rays you can see at the plot (there are 50 but here you see only from ray 20 until aprox.46).
I also have a line segment (blue line). How i can find that the blue line is betweem the ray 35 and the ray 36? Now I can say it only by looking the plot.

0 Comments
Answers (1)
Image Analyst
on 11 Jul 2019
Use pdist2() on the separate x and y coordinates of the two line vectors. (Note: Requires stats toolbox):
distances = pdist2([x1(:),y1(:)], [x2(:),y2(:)]);
minDistance = min(distances(:))
[rows, columns] = find(distances == minDistance);
fprintf('These points are closest (%f, %f) of curve 1 and (%f, %f) of line 2.\n',...
x1(rows(1)), y1(rows(1)), x2(columns(1)), y2(columns(1)));
0 Comments
See Also
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!