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

1 次查看(过去 30 天)
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,:);
  4 个评论

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2017-6-2
X1 = X ; % this your X coordinates, in which you want to remove one point
X1(Idx(1),:) = [] ; % remove the first index from Idx
  2 个评论
Peyman Obeidy
Peyman Obeidy 2017-6-3
with a bit of modification here is the code;
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);
% you are introduceing what needs to be delete, so if you want everything
% bigger than 4 you need to delet everything smaller than 4
Indx2=find(TableDisInd(:,2)<4);
TableDisInd2=TableDisInd(Indx2,:);
%use the first col of "TableDisInd2" to find the index in X table
Idx2=TableDisInd2(:,1);
X1 = X ; % this your X coordinates, in which you want to remove one point
%X1(Indx2(:,1),:) = [] ; % remove the first index from Idx
X1(Idx2(:,1),:) = [] ; % remove all the close distances from X list

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by