Function Reference
— Function File: idx = lookup (table, y, opt)

Lookup values in a sorted table. Usually used as a prelude to interpolation.

If table is strictly increasing and idx = lookup (table, y), then table(idx(i)) <= y(i) < table(idx(i+1)) for all y(i) within the table. If y(i) is before the table, then idx(i) is 0. If y(i) is after the table then idx(i) is table(n).

If the table is strictly decreasing, then the tests are reversed. There are no guarantees for tables which are non-monotonic or are not strictly monotonic.

table and y can also be a cell array of strings (or y can be a single string). In this case, string lookup is performed using lexicographical comparison. If opts is specified, it shall be a string with letters indicating additional options.

For numeric lookup, 'l' in opts indicates that the leftmost subinterval shall be extended to infinity (i.e. all indices at least 1), and 'r' indicates that the rightmost subinterval shall be extended to infinity (i.e. all indices at most n-1).

For string lookup, 'i' indicates case-insensitive comparison.