values - Values of dictionary - MATLAB (original) (raw)
Main Content
Values of dictionary
Since R2022b
Syntax
Description
`v` = values([d](#mw%5F31c4bc89-5d1f-481f-bbf4-55d628f5c4f6%5Fsep%5Fmw%5F6b2c4725-2753-4b6a-805b-39686bdc1868))
returns an array containing the values of the specified dictionary. Values are returned in the order in which the entries were added to the dictionary.
`v` = values([d](#mw%5F31c4bc89-5d1f-481f-bbf4-55d628f5c4f6%5Fsep%5Fmw%5F6b2c4725-2753-4b6a-805b-39686bdc1868),"cell")
optionally return the values as a cell array.
Examples
Create a dictionary containing three key-value pairs that map numbers to strings.
names = ["Unicycle" "Bicycle" "Tricycle"]; wheels = [1 2 3]; d = dictionary(wheels,names)
d =
dictionary (double ⟼ string) with 3 entries:
1 ⟼ "Unicycle"
2 ⟼ "Bicycle"
3 ⟼ "Tricycle"
Use values
to return an array containing the values stored in the dictionary.
v = 3×1 string "Unicycle" "Bicycle" "Tricycle"
Create a dictionary containing three key-value pairs that map numbers to strings.
names = ["Unicycle" "Bicycle" "Tricyle"]; wheels = [1 2 3]; d = dictionary(wheels,names)
d =
dictionary (double ⟼ string) with 3 entries:
1 ⟼ "Unicycle"
2 ⟼ "Bicycle"
3 ⟼ "Tricyle"
Use values
to return an array containing the values stored in the dictionary as a cell array.
v=3×1 cell array {["Unicycle"]} {["Bicycle" ]} {["Tricyle" ]}
Input Arguments
Dictionary, specified as a dictionary object. If d
is unconfigured, values
throws an error.
Extended Capabilities
Usage notes and limitations:
- If the code generator is unable to return the dictionary values as an array, code generation fails. In these situations, use the
"cell"
argument to return dictionary values as a cell array. - If you use it, the
"cell"
argument must be a constant at code generation time. - The code generator does not treat a dictionary as a constant, even if the dictionary is constant at code generation time. This means that the
values
function does not return a constant. You cannot pass the output of thevalues
function to a function that requires constant inputs. You cannot use the output of thevalues
function for operations that require constants, such as indexing into a heterogeneous cell array. The code generator also cannot perform optimizations that depend on constants, such as constant folding, on the output of thevalues
function.
For additional considerations that apply when generating C/C++ code for MATLAB® dictionaries, see Dictionary Limitations for Code Generation (MATLAB Coder).
Version History
Introduced in R2022b
You can generate C/C++ code for the dictionary values
function.