Since your points are equidistant you can use the value x
to find the index:
vIdx = 1+round(x*(numel(values)-1));
The idea is that you are dividing the interval [0, 1]
into numel(values)-1
equally sized intervals. Now by multiplying x
by that number you map the interval to [0, numel(values)-1]
where your points are mapped to integer values. Now using round
you get the closest one and by adding 1 you get the one-based index that MATLAB requires.