so I'm trying to find the minimum distance between each point in a large array with that of a smaller array. The following works for a single point.
m = [-3, -1, 1, 3];
r = [.2, -1, .39, 3.6, -1.8.....]
[minVal ind] = min((r(1) - m).^2))
What i'm trying to do it this:
[minVal ind] = min((r - m).^2))
Where it does (r(1) -m)^2, and finds the minimum, and then does (r(2) -m)^2, and finds the minimum, etc. I know this could be done in a for loop, I just thought there would be a more elegant solution. I hope that makes sense. Thanks for your time!
Try this:
Note that you could replace your distance function with
abs(x-y)instead of(x-y).^2for the same result, or even makeFby doingF=pdist2(m.',r.').