| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
k = keys(M)
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.
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 Juneaucontainers.Map, values(Map), size(Map), length(Map)isKey(Map), remove(Map), handle
![]() | keyboard | kron | ![]() |

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 |