Main Content

values

Return values of Map object

Description

example

Note

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

valueSet = values(M) returns all the values of the input Map object as a cell array.

example

valueSet = values(M,keySet) returns the values that correspond to the keys specified in the cell array keySet. The output argument valueSet has the same size as keySet.

Examples

collapse all

Create a Map object.

ids = [437 1089 2362];
names = {'Li, N.','Jones, R.','Sanchez, C.'};
M = containers.Map(ids,names)
M = 
  Map with properties:

        Count: 3
      KeyType: double
    ValueType: char

Return a cell array containing its values.

valueSet = values(M)
valueSet = 1x3 cell
    {'Li, N.'}    {'Jones, R.'}    {'Sanchez, C.'}

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 values that correspond to specified keys.

keySet = {'Jan','Feb'};
valueSet = values(M,keySet)
valueSet=1×2 cell array
    {[327.2000]}    {[368.2000]}

Return one value. Even when you specify one key, you must specify it as a cell array.

keySet = {'Apr'};
valueSet = values(M,keySet)
valueSet = 1x1 cell array
    {[178.4000]}

Input Arguments

collapse all

Input Map object.

Keys corresponding to values to return from the Map object, specified as a cell array.

Even when you specify keys as strings, the keys must be contained in a cell array.

Version History

Introduced in R2008b