Getting the minimum distance in a coordinates array
1 回表示 (過去 30 日間)
古いコメントを表示
Let's say I have this array of coordinates (values are (x,y)):
centers =
938 845
810 1012
147 875
1162 810
494 1039
383 897
203 1010
I need to pick 2 coordinates with the lowest difference on the X-axis (first column) because I need 2 points that are as closest as possible to each other. How can I do it?
0 件のコメント
回答 (1 件)
Paolo
2018 年 6 月 9 日
Your input:
x = [938;810;147;1162;494;383;203];
y = [845;1012;875;810;1039;897;1010];
Sort x:
[tmpx,i] = sort(x);
%Order y according to sorting index for x.
tmpy = y(i);
Your two points are:
P1 = [tmpx(1),tmpy(1)]
P2 = [tmpx(2),tmpy(2)]
Output:
P1 = 147 875
P2 = 203 1010
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!