MATLAB: How to script this: returns all the x coordinates that distance between X and Y are bigger than r distant

exclude the closest distance coordinates

I put together this, which is returning the y coordinates that are having greater distance than 2 e.g.
%
rng(1); % For reproducibility
X = randn(50,2);%GreenPeak
Y = randn(4,2);%RedPeak;
%imshow(Ifinalb); hold on ;
h = zeros(3,1);
figure;
h(1) = plot(X(:,1),X(:,2),'bx');
hold on;
h(2) = plot(Y(:,1),Y(:,2),'rs','MarkerSize',10);
%title('Heterogenous Data')
%%-----------------------
%Choose weights for each dimension, and specify the chi-square distance function. The distance function must:
%Take as input arguments one row of X, e.g., x, and the matrix Z.
%Compare x to each row of Z.
%Return a vector D of length $n_z$, where $n_z$ is the number of rows of Z.
%Each element of D is the distance between the observation corresponding to x and the observations corresponding to each row of Z
hold on
w = [2; 2];
chiSqrDist = @(x,Z)sqrt((bsxfun(@minus,x,Z).^2)*w);
%Find the indices of the three nearest observations in X to each
%observation in Y.k=3
k = 1;
[Idx,D] = knnsearch(X,Y,'Distance',chiSqrDist,'k',k);
%[Idx,D]= knnsearch(X,Y,'dist','cityblock','k',k);
TableDisInd(:,1)=Idx(:,1);
TableDisInd(:,2)=D(:,1);
Indx2=find(TableDisInd(:,1)>=2);
TableDisInd2=TableDisInd(Indx2,:);

Best Answer

X1 = X ; % this your X coordinates, in which you want to remove one point
X1(Idx(1),:) = [] ; % remove the first index from Idx