Sarah Latham
Change the passenger's first name to Anna Latham by overwriting the original value for
the A479GY key:
ticketMap('A479GY') = 'Anna Latham';
Verify the change:
ticketMap('A479GY')
ans =
Anna Latham
Modify Keys
To modify an existing key while keeping the value the same, first remove both the key and
its value from the Map. Then create a new entry, this time with the corrected key name.
Modify the ticket number belonging to passenger James Enright:
remove(ticketMap, '2R175');
ticketMap('2S185') = 'James Enright';
k = keys(ticketMap); v = values(ticketMap);
str1 = ' ''%s'' has been assigned a new\n';
str2 = ' ticket number: %s.\n';
fprintf(str1, v{1})
fprintf(str2, k{1})
'James Enright' has been assigned a new
ticket number: 2S185.
Modify Copy of Map
Because ticketMap is a handle object, you need to be careful when making copies of the
Map. Keep in mind that by copying a Map object, you are really just creating another
handle to the same object. Any changes you make to this handle are also applied to the
original Map.
Modify Keys and Values in Map