Reputation: 969
Lets say I have a dataset like below.
X = [170,85; 165,75; 180,100; 190,120; 160,80; 170,70];
a distance vector
Y = [10,20];
a data point
Z = [166,77];
I want to find all the points of X that fall within the distance Y from the point Z
Answer should be ans = [170,85; 165,75; 160,80; 170,70]
How can I do this in Matlab
Upvotes: 0
Views: 60
Reputation: 2149
a= X(abs(X(:,1)-Z(1))<=Y(1) & abs(X(:,2)-Z(2))<=Y(2),:)
EDIT
Multidimensional solution can look like this:
a= X(all(abs(X-ones(size(X,1),1)*Z) <= ones(size(X,1),1)*Y,2),:)
Upvotes: 1