values

Values stored in a containers.Map or dictionary.

Category: Language Fundamentals > Data Types

Syntax

v = values(M)

Returns all values, ordered by key.

v = values(M, keys)

Returns only the values of the given keys, in a cell array.

Description

A map keeps its keys sorted, so values(M) follows the order of keys(M): the first value belongs to the first key, and so on. This pairing makes it easy to walk through both together or to convert a map to a table.

For reading a single value, indexing with the key, M('a'), is simpler.

Input arguments

M
containers.Map object or dictionary.
keys
Cell array of keys to look up. A missing key raises an error.

Output arguments

v
For a containers.Map, a 1-by-N cell array; for a dictionary, an array of the value type.

Example

All values and selected ones

m = containers.Map({'a','b'}, [1 2]);
values(m)
values(m, {'b'})
Output
ans = 1×2 cell

    {[1]}    {[2]}
ans = 1×1 cell

    {[2]}

See also

keys isKey remove containers.Map dictionary