WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

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
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
DistanceFunction  
Applications  
Properties & Relations  
See Also
Related Guides
History
Cite this Page

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

Examples

open all close all

Basic Examples  (4)

Find the element nearest to 20:

Find the 3 elements nearest to 20:

Find which element is nearest to {2,3} in 2D:

Find nearest colors:

Find nearest strings:

Scope  (6)

Give the 3 nearest elements:

Give the elements within radius 2:

Give at most 3 nearest elements within radius 2:

Apply NearestTo to a NearestFunction expression:

The same result can be obtained by direct application of nf:

Return the index for the nearest string:

Return an Association giving the string element, index and distance:

Find the 3 elements nearest to 20, simultaneously reporting the elements and their distance to 20:

Find which element is nearest to {2,3} in 2D and return the appropriate label:

Compute the same result using an Association :

Find the element whose density is closest to a given value:

Options  (1)

DistanceFunction  (1)

By default, normal Euclidean distance is used for points:

Use the ManhattanDistance , which sums the length of each side:

The ChessboardDistance only takes into account the dimension with the largest separation:

Applications  (3)

Find nearest words in a dictionary:

Find the nearest image partition to a subimage:

Take the polygon of Mexico:

Compute the nearest of the points of that polygon from your current geo location:

Draw the geodesic from your location to that point:

Properties & Relations  (2)

In the case of a tie, all nearest elements are returned in order:

NearestTo [x][elems] effectively reverses the order of the first two arguments of Nearest :

Wolfram Research (2018), NearestTo, Wolfram Language function, https://reference.wolfram.com/language/ref/NearestTo.html.

Text

Wolfram Research (2018), NearestTo, Wolfram Language function, https://reference.wolfram.com/language/ref/NearestTo.html.

CMS

Wolfram Language. 2018. "NearestTo." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NearestTo.html.

APA

Wolfram Language. (2018). NearestTo. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NearestTo.html

BibTeX

@misc{reference.wolfram_2025_nearestto, author="Wolfram Research", title="{NearestTo}", year="2018", howpublished="\url{https://reference.wolfram.com/language/ref/NearestTo.html}", note=[Accessed: 16-November-2025]}

BibLaTeX

@online{reference.wolfram_2025_nearestto, organization={Wolfram Research}, title={NearestTo}, year={2018}, url={https://reference.wolfram.com/language/ref/NearestTo.html}, note=[Accessed: 16-November-2025]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /