keys
Description
Examples
Query Keys of Dictionary
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 keys
to return an array containing the keys stored in the dictionary.
k = keys(d)
k = 3×1
1
2
3
Return Keys of Dictionary as Cell Array
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 keys
with the optional input "cell"
to return an array containing the keys stored in the dictionary as a cell array.
k = keys(d,"cell")
k=3×1 cell array
{[1]}
{[2]}
{[3]}
Input Arguments
d
— Dictionary
dictionary
object
Dictionary, specified as a dictionary
object. If d
is unconfigured, keys
throws
an error.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
For code generation, you must use the
"cell"
argument.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
keys
function does not return a constant. You cannot pass the output of thekeys
function to a function that requires constant inputs. You cannot use the output of thekeys
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 thekeys
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 R2022bR2024b: Code generation support
You can generate C/C++ code for the dictionary keys
function.
See Also
dictionary
| entries
| values
| types
| numEntries
| isConfigured
| isKey
| keyHash
| keyMatch
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)