Create Map Object
A Map is an object of the Map class. It is defined within a MATLAB package called
containers. As with any class, you use its constructor function to create any new
instances of it. You must include the package name when calling the constructor:
newMap = containers.Map(optional_keys_and_values)
Construct Empty Map Object
When you call the Map constructor with no input arguments, MATLAB constructs an
empty Map object. When you do not end the command with a semicolon, MATLAB displays
the following information about the object you have constructed:
newMap = containers.Map
newMap =
Map with properties:
Count: 0
KeyType: char
ValueType: any
The properties of an empty Map object are set to their default values:
- Count = 0
- KeyType = 'char'
- ValueType = 'any'
Once you construct the empty Map object, you can use the keys and values methods to
populate it. For a summary of MATLAB functions you can use with a Map object, see
“Methods of Map Class” on page 14-5
Construct Initialized Map Object
Most of the time, you will want to initialize the Map with at least some keys and values at
the time you construct it. You can enter one or more sets of keys and values using the
syntax shown here. The brace operators ({}) are not required if you enter only one key/
value pair:
14 Map Containers