isKey - Determine if dictionary contains key - MATLAB (original) (raw)
Main Content
Determine if dictionary contains key
Since R2022b
Syntax
Description
tf = isKey([d](#mw%5Fe8bf96d2-f386-46ab-889c-698e75cc2ac8%5Fsep%5Fmw%5F6b2c4725-2753-4b6a-805b-39686bdc1868),[key](#mw%5F0d27f5f2-257a-447a-a0ed-f35b46044d57))
returns a logical 1
(true
) if the configured dictionary contains the specified key, and it returns a logical 0
(false
) otherwise. If d
is an unconfigured dictionary, isKey
throws an error.
If key
is an array that specifies multiple keys, thentf
is a logical array of the same size.
Examples
Create a dictionary containing several key-value pairs.
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"
Determine whether the dictionary has 1
as a key.
Search for multiple keys.
key = [1 2 3 4 5]; tf = isKey(d,key)
tf = 1×5 logical array
1 1 1 0 0
Input Arguments
Dictionary, specified as a dictionary object. If d
is unconfigured, isKey
throws an error.
Key set, specified as an array. The data type of key
must match or be convertible to the data type of keys in d
.
Extended Capabilities
Usage notes and limitations:
- 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
isKey
function does not return a constant. You cannot pass the output of theisKey
function to a function that requires constant inputs. You cannot use the output of theisKey
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 theisKey
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 isKey
function.