MATLAB: Selecting values of a vector

MATLABmatrixvector

Hi,
Is there a way to pick the element of a vector which is closest to 1.
Let's say A = [ 113; 14; 6; 43; 9; 2 ]
I was wondering if there's a method to pick the value which is closest to 1. which in this case is = 2
Thanks

Best Answer

[minA, minidx] = min(abs(A - 1));
A(minidx)