Closest value

Find the closest value to a given number in a vector

You are now following this Submission

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 (2026). Closest value (https://in.mathworks.com/matlabcentral/fileexchange/44505-closest-value), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
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.