0

I am looking to find the distance between a set of points and the coordinates of a grid.

x = 177136 x 1 
y = 177136 x 1

I have the following query points to which I am trying to find the distance to x and y;

xtrack = 1 x 1166
ytrack = 1 x 1166

I have tried this:

dist = pdist2([x, y], [xtrack, ytrack]); % find the distance for each query point       
[dist, nearestID] = min(distTRI); % find element number of the nearest point

My problem is pdist2 doesn't like that the column length is different. Any ideas how I can input a vector of points like this? I want to keep xtrack and ytrack and column vectors.

Thanks.

obchardon
  • 10,614
  • 1
  • 17
  • 33
nico1234
  • 9
  • 8
  • 2
    you can just apply the formula of the euclidian distance: `sqrt((x-xtrack).^2+(y-ytrack).^2)` and you will obtain a `177136x1166` distance matrix. By the way you obtain the same result with `pdist2([x,y],[xtrack;ytrack].')`. – obchardon Mar 08 '21 at 17:55
  • `pdist2` has no problem with the two inputs having different numbers of rows (try for example `pdist2(randn(5,2), randn(7,2))`). The problem seems to be that `xtrack`, `ytrack` are row vectors, not column vectors. Try `pdist2([x, y], [xtrack(:), ytrack(:)])` – Luis Mendo Mar 08 '21 at 19:21

0 Answers0