Hey all

I have two cells; cell A and cell B. Cell A is 11 x 1, and cell B is 200 x 1. These cells include tables.

Each table in both cells has a column named lat (latitude) and lon (longitude). Latitude and longitude are constant in each table but different in A and B.

I mean, I have some points (longitude and latitude) in cell A and some other points with different latitude and longitude in cell B.

I want to find which table in cell B is the nearest to the tables in cell A, based on latitude and longitude columns (Euclidean distance).

I want to store every two tables that are nearest to each other.

So, in the end, for every 11 tables in A I would have 11 other tables from B that are nearest to A tables.

dist = sqrt((A.lon - A.lon').^2 + (B.lat - B.lat').^2);

dist(dist == 0) = Inf;

[~,closest_id] = min(dist);

I attached A and B here.

Thank you all in advance.

## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505297-finding-nearest-tables-based-on-latitude-and-longitude-columns#comment_796909

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505297-finding-nearest-tables-based-on-latitude-and-longitude-columns#comment_796909

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505297-finding-nearest-tables-based-on-latitude-and-longitude-columns#comment_796916

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/505297-finding-nearest-tables-based-on-latitude-and-longitude-columns#comment_796916

Sign in to comment.