Home > vbmeg > functions > common > coordinate > vb_find_min_distance.m

vb_find_min_distance

PURPOSE ^

Find min distance point in y from x

SYNOPSIS ^

function [yindx, yout, ddmin] = vb_find_min_distance(x,y)

DESCRIPTION ^

 Find min distance point in y from x
 [yindx, yout, ddmin] = vb_find_min_distance(x,y)
 --- Input
 x : set of coordinate (N x D )
 y : set of coordinate (M x D )
 --- Output
 yout(n,:) : min distance point in y from x(n,:)
 yindx(n)  : min distance point index 
 ddmin(n)  : min distance from x(n,:)

  M. Sato  2006-2-3

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [yindx, yout, ddmin] = vb_find_min_distance(x,y)
0002 % Find min distance point in y from x
0003 % [yindx, yout, ddmin] = vb_find_min_distance(x,y)
0004 % --- Input
0005 % x : set of coordinate (N x D )
0006 % y : set of coordinate (M x D )
0007 % --- Output
0008 % yout(n,:) : min distance point in y from x(n,:)
0009 % yindx(n)  : min distance point index
0010 % ddmin(n)  : min distance from x(n,:)
0011 %
0012 %  M. Sato  2006-2-3
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 N  = size(x,1);
0018 M  = size(y,1);
0019 
0020 dd    = zeros(M,1);
0021 ddmin = zeros(N,1);
0022 yindx = zeros(N,1);
0023 
0024 for n=1:N
0025 %    xn = x(n,:);
0026 %    dd = (y(:,1) - xn(1)).^2 ...
0027 %       + (y(:,2) - xn(2)).^2 ...
0028 %       + (y(:,3) - xn(3)).^2;
0029     
0030     dd = sum(vb_repadd(y, -x(n,:) ).^2, 2);
0031     [ddmin(n) ,yindx(n)] = min(dd);
0032 end;
0033 
0034 if nargout == 1, return; end;
0035 
0036 yout = y(yindx,:);
0037 
0038 if nargout == 3, ddmin = sqrt(ddmin); end;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005