Modify Keys and Values in Map
NoteKeep in mind that if you have more than one handle to a Map, modifying the handle
also makes changes to the original Map. See “Modify Copy of Map” on page 14-17,
below.
Remove Keys and Values from Map
Use the remove method to delete any entries from a Map. When calling this method,
specify the Map object name and the key name to remove. MATLAB deletes the key and its
associated value from the Map.
The syntax for the remove method is
remove(mapName, 'keyname');
Start with the Map ticketMap :
ticketMap = containers.Map(...
{'2R175', 'B7398', 'A479GY', 'NZ1452'}, ...
{'James Enright', 'Carl Haynes', 'Sarah Latham', ...
'Bradley Reid'});
Remove one entry (the specified key and its value) from the Map object:
remove(ticketMap, 'NZ1452');
values(ticketMap)
ans =
'James Enright' 'Sarah Latham' 'Carl Haynes'
Modify Values
You can modify any value in a Map simply by overwriting the current value. The
passenger holding ticket A479GY is identified as Sarah Latham:
ticketMap('A479GY')
ans =
14 Map Containers