0

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

moCap
  • 969
  • 1
  • 14
  • 31

1 Answers1

1
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),:)
AVK
  • 2,130
  • 3
  • 15
  • 25
  • Ok. So, this works fine for the above example but I provided example just to clearify what I want to do. For my actual task I have a dataset with lot more dimensions. So, above method will require too much effort. I was looking for something like `rangesearch` Thanks anyway :) – moCap Oct 14 '16 at 06:02