フィルターのクリア

How to find which are the nearest points to the line segment?

11 ビュー (過去 30 日間)
ARGY B
ARGY B 2019 年 7 月 11 日
回答済み: Image Analyst 2019 年 7 月 11 日
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.

回答 (1 件)

Image Analyst
Image Analyst 2019 年 7 月 11 日
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)));

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by