MATLAB: How to find the value in a column that’s most close to a specific number

indexMATLAB

Without writing a loop, is there an easy way to find out the number in a column that's most close to a specific number?
For example, I have a column data A = [1;2;3;4;5;6;7]; It is always ranked in the order of small to large. Now I have a number 2.7. How do I find the index of the values in A that is most close to 2.7? We know in this case the answer should be A(3,1)=3. So how do I find the index "3" without writing a loop?

Best Answer

A = [1;2;3;4;5;6;7]
b=2.7
[~,idx]=min(abs(A-b))