This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Determine if Map object contains key


TF = isKey(M,keySet)



TF = isKey(M,keySet) returns 1 (true) if M contains the specified key, and returns 0 (false) otherwise.

If keySet is an array that specifies multiple keys, then TF is a logical array of the same size.


collapse all

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.

TF = isKey(M,'Feb')
TF = logical

Search for multiple keys.

keySet = {'Mar','Apr','May','Jun'};
TF = isKey(M,keySet)
TF = 1x4 logical array

   1   1   0   0

Input Arguments

collapse all

Input Map object.

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.

Introduced in R2008b