Skip to Main Content Skip to Search
Product Documentation

remove - Class: containers.Map
Package: containers

Remove key-value pairs from containers.Map object

Syntax

remove(mapObj,keySet)

Description

remove(mapObj,keySet) erases all specified keys, and the values associated with them, from mapObj. Input keySet can be 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 in mapObj to delete.

Examples

Remove Key-Value Pairs from a Map

Create a map and view the keys and the Count property:

myKeys = {'a','b','c','d'};
myValues = [1,2,3,4];
mapObj = containers.Map(myKeys,myValues);

mapKeys = keys(mapObj)
mapCount = mapObj.Count

The initial map contains four key-value pairs:

mapKeys = 
    'a'    'b'    'c'    'd'

mapCount =
                    4

Remove the pairs corresponding to keys b and d:

keySet = {'b','d'};
remove(mapObj,keySet)

mapKeys = keys(mapObj)
mapCount = mapObj.Count

The modified map contains two key-value pairs:

mapKeys = 
    'a'    'c'

mapCount =
                    2

See Also

containers.Map | isKey | keys | values

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS