This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Class: containers.Map
Package: containers

Determine if containers.Map object contains key


tf = isKey(mapObj,keySet)


tf = isKey(mapObj,keySet) looks for the specified keys in mapObj, and returns logical true (1) for the keys that it finds, and logical false (0) for those it does not. keySet is a scalar key or a cell array of keys.

Input Arguments


Object of class containers.Map.


Scalar value, character vector, or cell array that specifies keys to find in mapObj.

Output Arguments


Array of logical values. If keySet is a scalar or a character vector, tf is a scalar. Otherwise, tf has the same size and dimensions as keySet.


Find Keys in a Map

Construct a map that contains rainfall data for several months:

months =   {'Jan', 'Feb', 'Mar', 'Apr'};
rainfall = [327.2, 368.2, 197.6, 178.4];
mapObj = containers.Map(months,rainfall);

Determine if keys Apr, May, and Jun are in the map:

keySet = {'Apr','May','Jun'};
tf = isKey(mapObj,keySet)

This code returns 1-by-3 vector tf:

tf =

     1     0     0

Find a Single Key

Determine if mapObj from the previous example contains key Feb:

keySet = 'Feb';
tf = isKey(mapObj,keySet)

This code returns scalar tf:

tf =

Was this topic helpful?