Nearest

Nearest[{elem1,elem2,},x]
gives the list of to which x is nearest.

Nearest[{elem1v1,elem2v2,},x]
gives the corresponding to the to which x is nearest.

Nearest[{elem1,elem2,}{v1,v2,},x]
gives the same result.

Nearest[{elem1,elem2,}Automatic,x]
takes the to be successive integers i.

Nearest[data,{x1,x2,}]
effectively gives .

Nearest[data,x,n]
gives the n nearest to x.

Nearest[data,x,{n,r}]
gives the n or fewer nearest to x that are within radius r of x.

Nearest[data]
generates a NearestFunction[] that can be applied repeatedly to different x.

Details and OptionsDetails and Options

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Find the element nearest to 20:

In[1]:=
Click for copyable input
Out[1]=

Find the 3 elements nearest to 20:

In[2]:=
Click for copyable input
Out[2]=

Find which element is nearest to in 2D:

In[1]:=
Click for copyable input
Out[1]=

Find "nearest" strings:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Find nearest colors:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

Find the nearest image partition to a subimage:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Introduced in 2007
(6.0)
| Updated in 2014
(10.0)