This document presents code for quickly finding the index of the last value in a sorted array that is less than a given value x. It uses a binary search approach implemented recursively in MATLAB and as a MEX function for faster performance. Benchmarking shows the MEX version is much faster than the MATLAB implementation when performing many lookups on a large array.