How to script this: returns all the x coordinates that distance between X and Y are bigger than r distant ?
2 次查看(过去 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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Network Parameters 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!