Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Find all neighbors within specified distance using input data

`Idx = rangesearch(X,Y,r)`

```
[Idx,D] =
rangesearch(X,Y,r)
```

```
[Idx,D] =
rangesearch(X,Y,r,Name,Value)
```

For a fixed positive real value

`r`

,`rangesearch`

finds all the`X`

points that are within a distance`r`

of each`Y`

point. To find the*k*points in`X`

that are nearest to each`Y`

point, for a fixed positive integer*k*, use`knnsearch`

.`rangesearch`

does not save a search object. To create a search object, use`createns`

.

For an overview of the

*k*d-tree algorithm, see k-Nearest Neighbor Search Using a Kd-Tree.The exhaustive search algorithm finds the distance from each point in

`X`

to each point in`Y`

.

If you set the `rangesearch`

function `'NSMethod'`

name-value pair argument to the appropriate value (`'exhaustive'`

for an
exhaustive search algorithm or `'kdtree'`

for a *K*d-tree
algorithm), then the search results are equivalent to the results obtained by conducting a
distance search using the `rangesearch`

object function. Unlike the
`rangesearch`

function, the `rangesearch`

object function requires an `ExhaustiveSearcher`

or `KDTreeSearcher`

model object.

`ExhaustiveSearcher`

| `KDTreeSearcher`

| `createns`

| `knnsearch`

| `pdist2`