How to script this: returns all the x coordinates that distance between X and Y are bigger than r distant ?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Peyman Obeidy
am 2 Jun. 2017
Kommentiert: Peyman Obeidy
am 3 Jun. 2017
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 Kommentare
Akzeptierte Antwort
KSSV
am 2 Jun. 2017
X1 = X ; % this your X coordinates, in which you want to remove one point
X1(Idx(1),:) = [] ; % remove the first index from Idx
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Network Parameters finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!