Closest value

Find the closest value to a given number in a vector
309 Downloads
Updated 12 Feb 2014

View License

Given the number NUM, this function find the closest value to NUM in the vector VEC.

Only search within vector interval, and the vector must be non-monotonic decreasing.

Good for closest longitude/latitude searches etc.

Cite As

Håvard Falck (2024). Closest value (https://www.mathworks.com/matlabcentral/fileexchange/44505-closest-value), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.4.0.0

Should be faster, but still do the same thing.

1.3.0.0

Minor fixes.
Only search within vector interval.

1.1.0.0

Added support for NUM larger or smaller than VEC.