Main Content

keys

Return keys of Map object

Description

Note

dictionary is recommended over containers.Map because it accepts more data types as keys and values and provides better performance. (since R2022b)

keySet = keys(M) returns a cell array containing all the keys in the input Map object.

example

Examples

collapse all

Create a Map object.

months = {'Jan','Feb','Mar','Apr'};
rainfall = [327.2 368.2 197.6 178.4];
M = containers.Map(months,rainfall)
M = 
  Map with properties:

        Count: 4
      KeyType: char
    ValueType: double

Return a cell array containing its keys.

keySet = keys(M)
keySet = 1x4 cell
    {'Apr'}    {'Feb'}    {'Jan'}    {'Mar'}

Input Arguments

collapse all

Input Map object.

Version History

Introduced in R2008b