isKey

Class: containers.Map
Package: containers

Determine if containers.Map object contains key

Syntax

tf = isKey(mapObj,keySet)

Description

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

mapObj

Object of class containers.Map.

keySet

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

Output Arguments

tf

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

Examples

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 =
     1
Was this topic helpful?