Lookup values in a sorted table. Usually used as a prelude to interpolation.
If table is strictly increasing and
idx = lookup (table, y)
, thentable(idx(i)) <= y(i) < table(idx(i+1))
for ally(i)
within the table. Ify(i)
is before the table, thenidx(i)
is 0. Ify(i)
is after the table thenidx(i)
istable(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.