Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

keys (Map) - Return all keys of containers.Map object

Syntax

k = keys(M)

Description

k = keys(M) returns cell array k that contains all of the keys stored in Map object M.

Read more about Map Containers in the MATLAB Programming Fundamentals documentation.

Examples

Construct a Map object that relates states in the United States to their capital cities:

US_Capitals = containers.Map( ...
{'Georgia', 'Alaska', 'Vermont', 'Oregon'}, ...
{'Atlanta', 'Juneau', 'Montpelier', 'Salem'})

Use the keys and values methods to list all keys and values in the map:

keys(US_Capitals)
ans = 
    'Arizona'    'Nebraska'    'New York'    'Oregon'

values(US_Capitals)
ans = 
    'Phoenix'    'Lincoln'    'Albany'    'Salem'

Use the map to look up a capital when given a specific state:

sprintf('   The capital of %s is %s', ...
'Alaska', US_Capitals('Alaska'))
ans =
   The capital of Alaska is Juneau

See Also

containers.Map, values(Map), size(Map), length(Map)isKey(Map), remove(Map), handle

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS