isKey - Determine if Map object contains key - MATLAB (original) (raw)
Main Content
Determine if Map
object contains key
Syntax
Description
Note
dictionary is recommended overcontainers.Map
because it accepts more data types as keys and values and provides better performance. (since R2022b)
TF = isKey([M](#d126e926316),[keySet](#d126e926341))
returns 1
(true
) if M
contains the specified key, and returns 0
(false
) otherwise.
If keySet
is an array that specifies multiple keys, thenTF
is a logical array of the same size.
Examples
Create a Map
object containing several key-value pairs.
months = {'Jan','Feb','Mar','Apr'}; rainfall = [327.2 368.2 197.6 178.4]; M = containers.Map(months,rainfall)
M = Map with properties:
Count: 4
KeyType: char
ValueType: double
Determine whether m
has 'Feb'
as a key.
Search for multiple keys.
keySet = {'Mar','Apr','May','Jun'}; TF = isKey(M,keySet)
TF = 1×4 logical array
1 1 0 0
Input Arguments
Keys to search for in the Map
object, specified as a numeric scalar, character vector, string scalar, or cell array. To search for multiple keys, specify keySet
as a cell array—even when you specify keys as numeric scalars or strings.
Version History
Introduced in R2008b