MATLAB: Find the two nearest points from an array given a value

arrayclosest pointdsearchnMATLAB

Hello,
Currently I have an 87×1 array called A.
A = 0.1334
0.1338
0.1348
0.1386
0.1444
0.1448
0.1452
0.1459
0.1469
0.1478
0.1488
I now have a value of 0.1400
What I want from A is the two nearest values to this number. In this case, it should be 0.1386 and 0.1444
I have the following code below which I have been trying to get to work:
k = dsearchn(A,0.1400)
This gives me 4 as the output which makes sense as the 4th row in array A has 0.1386 which is one of the closest.
However, how am I able to get the second closest of 0.1444?

Best Answer

[~,k] = mink(abs(A-0.1400),2);