lookup
Find value in dictionary by key.
📝Syntax
value = lookup(d, key)
value = lookup(d, key, 'FallbackValue', fallback)
📥Input Arguments
Parameter Description
d scalar: dictionary object.
key key type must match or be convertible to the data type of keys in d.
fallback scalar: Fallback value
📤Output Arguments
Parameter Description
value value.
📄Description

value = lookup(d, key) retrieves the value associated with the given key in dictionary d.

If the key does not exist, an error is raised.

value = lookup(d, key) is equivalent to value = d[key].

value = lookup(d, key, 'FallbackValue', fallback) specifies a fallback value to return if the key is not found in d.

lookup function only validates the fallback if it is needed. An error is raised only if the key is not found and no valid fallback is provided.

💡Examples
names = ["Apple" "Banana" "Kiwi"];
wheels = [1 2 3];
d = dictionary(wheels, names)
v = lookup(d,[3,5], 'FallbackValue', "Orange")
🔗See Also
dictionaryremoveinsert
🕔Version History
Version Description
1.5.0 initial version
Edit this page on GitHub