Closest value(s) from a list
Returns the closest value from a list
Syntax
c = closest(a,b); returns the closest c value in a for each value in b
[c,i] = closest(a,b); returns the index i of the closest value in a for each value in b
[c,i,d] = closest(a,b); returns the difference d of the closest value in a for each value in b
Example
[cvalue, cindex cdiff] = closest([-8 2 5.5 12 45 20 100],[-15 2.3 10 50])
cvalue =
-8 2 12 45
cindex =
1 2 4 5
cdiff =
7.0000 0.3000 2.0000 5.0000
Cite As
Javier Lopez-Calderon (2024). Closest value(s) from a list (https://www.mathworks.com/matlabcentral/fileexchange/31145-closest-value-s-from-a-list), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Mathematics > Sparse Matrices >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |