entries - Key-value pairs of dictionary - MATLAB (original) (raw)
Main Content
Key-value pairs of dictionary
Since R2022b
Syntax
Description
`E` = entries([d](#mw%5F820daf04-84cc-4e51-84ca-ac2dc2d5b1e1%5Fsep%5Fmw%5F6b2c4725-2753-4b6a-805b-39686bdc1868))
returns a table containing the key-value pairs of the specified dictionary. Entries are returned in the order in which the entries were added to the dictionary.
`E` = entries([d](#mw%5F820daf04-84cc-4e51-84ca-ac2dc2d5b1e1%5Fsep%5Fmw%5F6b2c4725-2753-4b6a-805b-39686bdc1868),[format](#mw%5F17e62208-304f-434f-b01c-985fc37566a0))
specifies the output format
as a table or a structure. For example,entries(d,"struct")
returns a structure containing the key-value pairs of d
. Use this option for data types that are not compatible with tables.
Examples
Create a dictionary containing several key-value pairs.
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 entries
to return a table containing the entries stored in d
.
E=3×2 table
Key Value
___ __________
1 "Unicycle"
2 "Bicycle"
3 "Tricyle"
Create a dictionary containing several key-value pairs.
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 entries
and specify the output format as "struct"
to return a struct
array containing the entries stored in d
.
E=3×1 struct array with fields: Key Value
Input Arguments
Dictionary, specified as a dictionary object. If d
is unconfigured, entries
throws an error.
Output format, specified as one of these values:
"table"
— Return key-value pairs in a table. This format is the default output format."struct"
— Return ann
-by-1 struct array, where each of then
struct
elements has the fieldskey
andvalue
corresponding to each of then
entries in the specified dictionary. Use this option for data types that are not compatible with tables."cell"
— Return key-value pairs in an
-by-2 cell array wheren
is the number of entries, the first column contains keys, and the second column contains values.
Extended Capabilities
Usage notes and limitations:
- The
format
argument must be constant. - If the
format
argument is"table"
, the dictionary cannot be empty at runtime. Dictionary keys and values must be numeric types, character arrays, structures, cell arrays, or enumerations. - If the
format
argument is"cell"
, all keys and values must have the same type. - 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
entries
function does not return constants. You cannot pass the output of theentries
function to a function that requires constant inputs. You cannot use the output of theentries
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 theentries
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 entries
function.