values - Return values of Map object - MATLAB (original) (raw)
Main Content
Return values of Map
object
Syntax
Description
Note
dictionary is recommended overcontainers.Map
because it accepts more data types as keys and values and provides better performance. (since R2022b)
valueSet = values([M](#d126e1973752))
returns all the values of the input Map
object as a cell array.
valueSet = values([M](#d126e1973752),[keySet](#d126e1973777))
returns the values that correspond to the keys specified in the cell arraykeySet
. The output argument valueSet
has the same size as keySet
.
Examples
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 = 1×3 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 = 1×1 cell array {[178.4000]}
Input Arguments
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