dictionary.lookup
dictionary: v = lookup (d, keys)
dictionary: v = lookup (…, 'FallbackValue', fallback)
Return the values of keys.
v = lookup (d, keys) returns the values of
keys, an array of keys, in an array of the same shape, as
d(keys) does; a key not in d is an error.
v = lookup (…, returns fallback for each key not in d
instead. fallback is a single value, converted to the value type
of d, so that a dictionary of 'FallbackValue',
fallback)'cell' values needs a cell;
it is checked only when some key is missing. The option name is
matched in any case.
d must be configured.
See also: dictionary.isKey, dictionary.insert, dictionary.values
Source Code: dictionary
lookup returns the values of keys as indexing does, and a key not in the dictionary is an error unless a 'FallbackValue' is given.
price = dictionary (string ({'tea', 'coffee'}), [2.5, 3.2])
price =
dictionary (string ⟼ double) with 2 entries:
"tea" ⟼ 2.5000
"coffee" ⟼ 3.2000
lookup (price, {'coffee', 'tea'})
ans = 3.2000 2.5000
lookup (price, {'tea', 'cocoa', 'coffee'}, 'FallbackValue', NaN)
ans = 2.5000 NaN 3.2000