k-Wave Toolbox


Return the closest value in a matrix.


value = findClosest(A, a)
[value, index] = findClosest(A, a)


findClosest returns the value and index of the item in A that is closest to the value a. For vectors, value and index correspond to the closest element in A. For matrices, value and index are row vectors corresponding to the closest element from each column. For N-D arrays, the function finds the closest value along the first non-singleton dimension. If there is more than one element with the closest value, the index of the first one is returned.


A matrix to search
a value to find


value value in A that is closest to a
index the index of a within A

See Also