function [rd1,rd2,Inn1p1]=falnei2(x,y,yrow,yp1,yp1row,idx)
%                                  written by N. Chino on April 10, 2017
%                                  revised by N. Chino on April 15, 2017
%                                  revised by N. Chino on May 1, 2017
% detection of the distances between a specified data point and the
% nearest neighbors in embedded dimensions, dim and dim+1, from a given 
% original one-dimensiona time signals.
% Input arguments
%  (1) x is the original time series with length N. 
%  (2) y is the dim-dimensional embedded coordinates
%  (3) yrow is the size of y.
%  (4) yp1 is the (dim+1)-dimensional embedded coordinates.
%  (5) yp1row is the size of yp1.
%  (6) idx is number of the specified point as a query point in the
%      embedded dimension.
% output arguments
%  (1) rd1 is the distance between the specified point, idx, and the
%      nearest neighber point in dimension, dim.
%  (2) rd2 is the distance between the specified point, idx, and the
%      nearest neighber point in dimension, dim+1.
%  (3) Inn1p1 is the index of the nearest neighbor in dimension, dmp1.
%
  T=y(~ismember(1:yrow,idx),:);  % training data except the query data in dim
  Q=y(idx,:); % query data in dimension, dim
  Md1KDT=KDTreeSearcher(T);
  [Inn1,rd1]=knnsearch(Md1KDT,Q);  % nearest neighber only
  %
  Tp1=yp1(~ismember(1:yp1row,idx),:);  % training data except query in dmp1
  Qp1=yp1(idx,:); % query data in dimension, dmp1
  Md1KDTp1=KDTreeSearcher(Tp1);
  [Inn1p1,rd2]=knnsearch(Md1KDTp1,Qp1);  % nearest neighber only


    
    

