Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Finding the minumum distance for LOTS of points
Replies: 0

 Bruce Bowler Posts: 303 Registered: 12/7/04
Finding the minumum distance for LOTS of points
Posted: Apr 8, 2013 11:44 AM

I have a 80,000+ element vector which are indices into 2 512x640 arrays
(one is latitude, the other longitude, let's call them alat and alon).

I have 2 other arrays that are 666x730. They are also latitude and
longitude (lets call these blat and blon). There's a 3rd 666x730 array
called data.

For each of the positions indicated in alat and alon, I want to find the
closest position in blat and blon and set the corresponding element in
data to nan.

What I have so far is...

for ix = 1:numel(nans)
dist = distance(alat(nans(ix)),alon(nans(ix)),blat,blon);
[~,closest] = min(min(dist));
data(closest) = nan;
end

It appears to be working, but molasses in winter doesn't even begin to
describe the speed.

Is there a better way to approach this?

TIA,
Bruce