Closest

Finds the value in an array X closest to the scalar b.

You are now following this Submission

Given a vector or matrix X, CLOSEST(X,b) finds the element in X that is nearest to the scalar b.

Example:

>> X = [-1 -2 6.14 9];
>> b = pi;
>> c = closest(X,b)

c =
6.14

Cite As

Matt (2026). Closest (https://www.mathworks.com/matlabcentral/fileexchange/42121-closest), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Linear Algebra in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.1.0.0

simpler algorithm, thanks to comment

1.0.0.0