Documentation

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.

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, character vector, 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
Was this topic helpful?