MATLAB: Hi..lets say there i a vector x=[1:3:50]..how can i find closest number to 25 in this vector using find?

finding the closest number

hi..lets say there is a vector x=[1:3:50]..how can i find closest number to 25 in this vector using find??

Best Answer

>> val = 26;
>> vec = 1:3:50;
>> [~,idx] = min(abs(vec-val));
>> vec(idx)
ans = 25