MATLAB: Find nearest value to specific number

arraycertainclosestfindindexnearestspecificvalue

Hello, I have an array with 20 values of steps per minute. I already know that the perfect outcome of one of these values is 33spm. But unfortunately 33spm is not in the array 34.8 is which is the closest to 33. What is the code to find the value closest to 33?
The ideal answer would be:
ClosestValue = 34.8
Could someone help me please?

Best Answer

Try the following approach:
a=[34.8 31 29 26.7 39.5];%dummy data

n=33;
[val,idx]=min(abs(a-n));
minVal=a(idx)
Edit after Jan's warning(multiple values)
a=[34.8 31.2 29 26.7 39.5];%dummy data
n=33;
[~,~,idx]=unique(round(abs(a-n)),'stable');
minVal=a(idx==1)