Home > omviz > nearxy.m

nearxy

PURPOSE ^

NEARXY finds the indices of (x,y) that are closest to the point (x0,y0).

SYNOPSIS ^

function [index,distance]=nearxy(x,y,x0,y0,dist);

DESCRIPTION ^

 NEARXY  finds the indices of (x,y) that are closest to the point (x0,y0).
        [index,distance]=nearxy(x,y,x0,y0) finds the closest point and
                                           the distance
        [index,distance]=nearxy(x,y,x0,y0,dist) finds all points closer than
                                           the value of dist.
 rsignell@crusty.er.usgs.gov

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [index,distance]=nearxy(x,y,x0,y0,dist);
0002 % NEARXY  finds the indices of (x,y) that are closest to the point (x0,y0).
0003 %        [index,distance]=nearxy(x,y,x0,y0) finds the closest point and
0004 %                                           the distance
0005 %        [index,distance]=nearxy(x,y,x0,y0,dist) finds all points closer than
0006 %                                           the value of dist.
0007 % rsignell@crusty.er.usgs.gov
0008 %
0009 distance=sqrt((x-x0).^2+(y-y0).^2);
0010 if (nargin > 4),
0011   index=find(distance<=dist);     %finds points closer than dist
0012 else,
0013   index=find(distance==min(distance));  % finds closest point
0014   index=index(1);
0015 end
0016 distance=distance(index);

Generated on Thu 01-Dec-2005 08:50:35 by m2html © 2003