dictionary
Object that maps unique keys to values
Description
A dictionary is useful for fast look up of values in a larger set. A dictionary is a map that stores data as values, which can be accessed using corresponding unique keys. Each pair of keys and values is an entry.
Creation
Description
creates a dictionary with specified keys and values. The resulting dictionary
d
= dictionary(keys
,values
)d
is a 1-by-1 scalar object. If multiple values are assigned to the
same key, then only the last of those values is assigned. New assignments to an existing
key overwrite the value for that entry.
keys
and values
must be the same size unless
values
is a scalar, where each element of keys
becomes a key for values
. When keys and values are arrays, the number
of entries is equal to the number of key-value pairs.
Dictionaries are typed based on their entries. All keys and all values in a dictionary must share respective data types or be able to be converted to the configured data type. If parts of a new entry do not share the configured data types then MATLAB attempt a conversion. Keys and values do not need to be of the same data type. Values of different types can be added to a dictionary if they are contained in a cell array.
creates a dictionary with specified key-value pairs. If multiple instances of the same key
are specified then only the last key-value pair is assigned.d
= dictionary(k1,v1,...,kN,vN
)
creates an unconfigured
dictionary with no keys or values. d
= dictionary
When a dictionary is created without inputs it is unconfigured and has no types. Adding entries to an unconfigured dictionary specifies a data type for the keys and a data type for the values.
Input Arguments
Object Functions
entries | Key-value pairs of dictionary |
keys | Keys of dictionary |
values | Values of dictionary |
types | Types of dictionary keys and values |
numEntries | Number of key-value pairs in dictionary |
isConfigured | Determine if dictionary has types assigned to keys and values |
isKey | Determine if dictionary contains key |
Examples
Version History
Introduced in R2022b
See Also
entries
| keys
| values
| types
| numEntries
| isConfigured
| isKey
| keyHash
| keyMatch