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.

example

Examples

collapse all

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

collapse all

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

expand all

Usage notes and limitations:

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

expand all

You can generate C/C++ code for the dictionary isKey function.