NearestTo

NearestTo[x]

is an operator form that yields Nearest[elems,x] when applied to a list elems.

NearestTo[x,n]

is an operator form that yields Nearest[elems,x,n] when applied to a list elems.

NearestTo[x,{n,r}]

is an operator form that yields Nearest[elems,x,{n,r}] when applied to a list elems.

Details and Options

  • NearestTo works for a variety of data, including numerical, geospatial, textual and visual, as well as dates and times.
  • NearestTo[x][elems] is equivalent to NearestTo[elems,x].
  • NearestTo[x,nr][elems] is equivalent to NearestTo[elems,x,nr], where nr is an integer n or a pair {n,r}.
  • NearestTo[x][nf] for a NearestFunction object nf is equivalent to nf[x].
  • NearestTo[x,nr][nf] for a NearestFunction object nf is equivalent to nf[x,nr], where nr is an integer n or a pair {n,r}.

Examples

open allclose all

Basic Examples  (4)

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 {2,3} in 2D:

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

Find nearest colors:

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

Find nearest strings:

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

Scope  (6)

Options  (1)

Applications  (3)

Properties & Relations  (2)

See Also

Nearest  EqualTo  GeoNearest  RegionNearest  FeatureNearest  NearestFunction

Introduced in 2018
(11.3)