


MINDIST Finds indices of closest vectors. YINDS = MINDIST(XLIST,YLIST), where XLIST is an M x D matrix and Y is N x D, returns an M x 1 vector YINDS such that YINDS(i) is the row number in YLIST that has the minimum (Euclidean) distance to the i^th row in XLIST. [YINDS,DISTS] = MINDIST(XLIST,YLIST) also returns the M x 1 vector DISTS such that DISTS(i) is the (Euclidean) distance between YLIST(YINDS(i),:) and XLIST(i,:). [...] = MINDIST(XLIST) is equivalent to MINDIST(XLIST,XLIST).


0001 function [yinds,dists] = mindist(X,Y) 0002 %MINDIST Finds indices of closest vectors. 0003 % YINDS = MINDIST(XLIST,YLIST), where XLIST is an M x D matrix and Y is 0004 % N x D, returns an M x 1 vector YINDS such that YINDS(i) is the row 0005 % number in YLIST that has the minimum (Euclidean) distance to the i^th 0006 % row in XLIST. 0007 % 0008 % [YINDS,DISTS] = MINDIST(XLIST,YLIST) also returns the M x 1 vector 0009 % DISTS such that DISTS(i) is the (Euclidean) distance between 0010 % YLIST(YINDS(i),:) and XLIST(i,:). 0011 % 0012 % [...] = MINDIST(XLIST) is equivalent to MINDIST(XLIST,XLIST). 0013 0014 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Parse Inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%% 0015 if (nargin < 2), Y = X; end; 0016 [M,D1] = size(X); 0017 [N,D2] = size(Y); 0018 if (D1~=D2), error('X and Y must have the same number of columns.'); end; 0019 if (~isreal(X) || ~isreal(Y) || ~isa(X,'double') || ~isa(Y,'double')) 0020 error('Input matrices must be real-valued matrices of type double.'); 0021 end 0022 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%% Do the Computation %%%%%%%%%%%%%%%%%%%%%%%%%% 0024 [yinds,dists] = CORE_mindist(X,Y); 0025 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Clean Up %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 if (nargin < 2), clear dists; 0028 else dists = sqrt(dists); 0029 end;