m = containers.Map()
m = containers.Map(keys, values)
m = containers.Map('KeyType', keyType, 'ValueType', valueType)
| Parameter | Description |
|---|---|
| keys | cell array of character vectors, character vector, string array, or numeric array. |
| values | scalar, array, or cell array of values. |
| keyType | character vector or string scalar that specifies the key type: char, double, single, int32, uint32, int64, or uint64. |
| valueType | character vector or string scalar that specifies the value type: any, char, double, single, int32, uint32, int64, uint64, logical, int8, or uint8. |
| Parameter | Description |
|---|---|
| m | scalar containers.Map object. |
m = containers.Map() creates an empty map with character-vector keys and values of any type.
m = containers.Map(keys, values) creates a scalar map from key-value pairs. Keys must be unique in the resulting map. If the same key appears more than once during construction, only the last value is kept.
If values is scalar and several keys are provided, the scalar value is assigned to each key. Otherwise the number of keys and values must match.
m = containers.Map('KeyType', keyType, 'ValueType', valueType) creates an empty typed map. The properties Count, KeyType, and ValueType are read-only.
When keys are provided as logical, int8, uint8, int16, or uint16 arrays, the inferred key type is double.
Values are accessed with parenthesis indexing, for example m('name'). Assigning m(key) = value inserts a new entry or replaces an existing value. The remove method deletes entries.
The keys and values methods return cell arrays. The isKey method checks whether keys are present and accepts a scalar key or a cell array of keys.
m = containers.Map({'apple', 'banana'}, [10 20])
m('apple')
m('banana') = 25
isKey(m, {'apple', 'kiwi'})
keys(m)
values(m)
m = containers.Map('KeyType', 'char', 'ValueType', 'any')
m('payload') = struct('name', 'Nelson', 'value', [1 2 3])
m.Count
m.ValueType
m = containers.Map([1 2 3], {'one', 'two', 'three'})
m(2)
remove(m, 1)
m.Count
| Version | Description |
|---|---|
| 2.0.0 | containers.Map class |