Closest

Version 1.1.0.0 (1.17 KB) by Matt
Finds the value in an array X closest to the scalar b.
479 Downloads
Updated 7 Jun 2013

View License

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 (2024). Closest (https://www.mathworks.com/matlabcentral/fileexchange/42121-closest), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Linear Algebra in Help Center and MATLAB Answers
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.1.0.0

simpler algorithm, thanks to comment

1.0.0.0