function [min_hamming_dist,I,matched]=minhamming_dist(Target,B,k)
        if ~exist('B','var')      
			[min_hamming_dist,I]=min((squareform(pdist(Target,'hamming'))+eye(size(Target,1)))*size(Target,2));
			matched=[];
		else 

			[min_hamming_dist,I]=min(pdist2(Target,B,'hamming')*size(Target,2));
			if exist('k','var')
				matched=I.*(sum(pdist2(Target,B,'hamming')*size(Target,2)==min_hamming_dist)==1).*(min_hamming_dist<=k);
			else
				matched=[];
			end
        end
		
end
