Code covered by the BSD License  

Highlights from
Closest value(s) from a list

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 1.41 KB File ID: #31145

Closest value(s) from a list

by Javier Lopez-Calderon

 

22 Apr 2011

Returns the closest value from a list for each target value

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File  
Everyone's Tags
closest, find, min, nearest, vector
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.

Contact us