%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function n = findclosest( x,y, x1,y1 ) % n = findclosest( x,y, x1,y1 ) % (x,y) are lists of coordinates, x(i) corresponds to y(i) % (x1,y1) coordinates of point we're looking for % n location in list of closest point in (x,y) to (x1,y1) % % finds the coordinates nearest to input point,returns their location in % the list of coordinates % method: find minimum sum of squares of differences xtemp = x - x1; xtemp = xtemp .* xtemp; ytemp = y - y1; ytemp = ytemp .* ytemp; temp = xtemp + ytemp; [minval,n] = min(temp);