This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Return values of Map object


valueSet = values(M)
valueSet = values(M,keySet)



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


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.


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 array
    {'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 = 1x2 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

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.

Introduced in R2008b