フィルターのクリア

Find closest values in an array of x and y coordinated compared to a given set of coordinates

14 ビュー (過去 30 日間)
Christina
Christina 2015 年 6 月 15 日
コメント済み: dpb 2015 年 6 月 15 日
Hello all,
I've got two vectors of coordinates
x = linspace(400000,500000,100) and
y = linspace(100000,200000,100)
*********
I've got the given coordinates of a point
x_coord= 406000 and y_coord = 170000 and I'd like to find the position/index of the BOTH vectors x and y that are CLOSER to the given coordinate point.
********
I need an index that would fulfill BOTH the nearest values of x and y and at the end I'd get only one index, not two different indices for vectors x and y.
I know that if I had just one vector, I could use the commands:
[c_x index_x] = min(abs(x_coord-x));
[c_y index_y] = min(abs(y_coord-y));
But I don't need that now.
**********
Any thoughts on that?

回答 (2 件)

Christina
Christina 2015 年 6 月 15 日
Actually I found the solution:
I created a table with the x and y coordinates:
The small code is:
*********
table[x y];
[d,p] = min((table(:,1)-x_coord).^2 + (table(:,2)-y_coord).^2);
**************
and p gives the index in 'table' matrix that meets the condition of getting the minimum distance between the point (x_coord,y_coord) and both x and y vectors

dpb
dpb 2015 年 6 月 15 日
See
doc pdist2
  2 件のコメント
Christina
Christina 2015 年 6 月 15 日
Hello
I tried the 'pdist2' command, but when I typed
[D,I] = pdist2(abs(x-x_coord),abs(y-y_coord),distance,'Smallest',k) ;
I get the error that there are not enough input arguments.
Do you know what would be the solution to that?
dpb
dpb 2015 年 6 月 15 日
Rows in {X,Y} to pdist2 are observations so
[dmin,imin]=pdist2([x y],[x0 y0],'euclidean','smallest',1);
is the result the same as your other solution. Not sure which is quicker...

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

カテゴリ

Help Center および File ExchangeEarth, Ocean, and Atmospheric Sciences についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by