"Airballman " <airballman@hotmail.com> wrote in message <hsqtl0$ehc$1@fred.mathworks.com>...
> "Ram Lakshmi" <ram.gopal@nsn.com> wrote in message <hsqr9u$phf$1@fred.mathworks.com>...
> > Hello,
> >
> > I have a point pt( x,y) and an array A(X,Y).
> >
> > The array A is around 1000 or more elements.
> >
> > I wanted to know the element in A that gives the shortest distance to the point pt.
> >
> > I tried to use the for loop and computed the normal distance formula but it takes longer compute time.
> >
> > Is there any inbuilt function to do this? Can someone share the code.
> >
> > Thanks and Regards
> > R.
>
> Hi,
>
> Couldn't the nearest_point file help you? It seems like it is roughly what you are trying to do :)
>
> Here is the link :
> http://www.mathworks.com/matlabcentral/fileexchange/8939nearestpoint
>
>
>
> C U
Hello,
The following the code that I wrote, and the results are coming differently with nearestpoint.
N = 1000;
vec_A = rand(N,2); % random N points
pt = rand(1, 2);% Point
min_distance = 100; % start with some random value as intial distance
for index = 1: N
dis = sqrt(( (vec_A(index,1)  pt (1,1)) ^2) + ((vec_A(index,2)  pt (1,2))^2));
dis
if (dis < min_distance)
min_distance = dis;
end
end
sprintf ('Minimum distance from the point p to vec is [%d]', min_distance)
Any help would be appreciated.
Thanks and Regards
R
