Home > functions > common > coordinate > vb_find_close_points.m

vb_find_close_points

PURPOSE ^

Find close distance points in y from x

SYNOPSIS ^

function [yindx, ddmin] = vb_find_close_points(x,y,Nnear)

DESCRIPTION ^

 Find close distance points in y from x
 [yindx, ddmin] = vb_find_close_points(x,y,Nnear)
 --- Input
 x : set of coordinate (N x D )
 y : set of coordinate (M x D )
 Nnear : Number of close points for each x(n,:)
 --- Output
 yindx(n,:)  : close point index in y for x(n,:) [N x Nnear]
 ddmin(n,:)  : close point distance from x(n,:)

  M. Sato  2008-8-1

 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, ddmin] = vb_find_close_points(x,y,Nnear)
0002 % Find close distance points in y from x
0003 % [yindx, ddmin] = vb_find_close_points(x,y,Nnear)
0004 % --- Input
0005 % x : set of coordinate (N x D )
0006 % y : set of coordinate (M x D )
0007 % Nnear : Number of close points for each x(n,:)
0008 % --- Output
0009 % yindx(n,:)  : close point index in y for x(n,:) [N x Nnear]
0010 % ddmin(n,:)  : close point distance from x(n,:)
0011 %
0012 %  M. Sato  2008-8-1
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 if ~exist('Nnear','var'), Nnear=3; end;
0018 
0019 N  = size(x,1);
0020 M  = size(y,1);
0021 
0022 dd    = zeros(M,1);
0023 ddmin = zeros(N,Nnear);
0024 yindx = zeros(N,Nnear);
0025 
0026 for n=1:N
0027     dd = sum(vb_repadd(y, -x(n,:) ).^2, 2);
0028     [dd, ix] = sort(dd);
0029     
0030     yindx(n,:) = ix(1:Nnear)';
0031     ddmin(n,:) = dd(1:Nnear)';
0032 end;
0033 
0034 if nargout == 1, return; end;
0035 if nargout == 2, ddmin = sqrt(ddmin); end;

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005