MATLAB: Smallest n such that vector(n) < a

vector

hi,
is there a efficient way that given a vector "vec" whose elements are monotonic increasing i can find the smallest index such that vec(n) < a. where "a" is some given value.

Best Answer

x = 1:100;
a = 50;
[val,idx] = find(x<a,1,'last');
idx is the index of vec() and val is the value
If the values in the vector are monotonically increasing as you describe, then the 'last' option gives you the last index. Did you really mean you want the "smallest"?