Map to Cell Array
As with structures, you can also map to a cell array in a Map object. Continuing with the airline
example of the previous sections, some of the passengers on the flight have “frequent flyer” accounts
with the airline. Map the names of these passengers to records of the number of miles they have used
and the number of miles they still have available:
accountMap = containers.Map( ...
{'Susan Spera','Carl Haynes','Anna Latham'}, ...
{{247.5, 56.1}, {0, 1342.9}, {24.6, 314.7}});
Use the Map to retrieve account information on the passengers:
name = 'Carl Haynes';
acct = accountMap(name);
fprintf('%s has used %.1f miles on his/her account,\n', ...
name, acct{1})
fprintf(' and has %.1f miles remaining.\n', acct{2})
Carl Haynes has used 0.0 miles on his/her account,
and has 1342.9 miles remaining.
See Also
keys | isKey | values | containers.Map | struct | cell
Related Examples
•
“Create Map Object” on page 14-6
•
“Structure Arrays” on page 11-2
•
“Create Cell Array” on page 12-3
•
“Examine Contents of Map” on page 14-8
•
“Read and Write Using Key Index” on page 14-9
•
“Modify Keys and Values in Map” on page 14-13
14 Map Containers
14-16
Précédent

- 584/1450

Suivant