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.

remove

Delete key-value pairs from Map object

Syntax

remove(M,keySet)

Description

example

remove(M,keySet) deletes the specified keys, and the values associated with them, from the input Map object.

Examples

collapse all

Create a Map object. Display its keys and values.

ids = [437 1089 2362];
names = {'Li, N.','Jones, R.','Sanchez, C.'};
M = containers.Map(ids,names)
M = 
  Map with properties:

        Count: 3
      KeyType: double
    ValueType: char

keys(M)
ans = 1x3 cell array
    {[437]}    {[1089]}    {[2362]}

values(M)
ans = 1x3 cell array
    {'Li, N.'}    {'Jones, R.'}    {'Sanchez, C.'}

Remove a key-value pair. Display the updated keys and values.

remove(M,2362);
keys(M)
ans = 1x2 cell array
    {[437]}    {[1089]}

values(M)
ans = 1x2 cell array
    {'Li, N.'}    {'Jones, R.'}

Create a Map object.

months = {'Jan','Feb','Mar','Apr'};
rainfall = [327.2 368.2 197.6 178.4];
M = containers.Map(months,rainfall);
keys(M)
ans = 1x4 cell array
    {'Apr'}    {'Feb'}    {'Jan'}    {'Mar'}

values(M)
ans = 1x4 cell array
    {[178.4000]}    {[368.2000]}    {[327.2000]}    {[197.6000]}

To remove multiple key-value pairs, specify the keys as a cell array.

keySet = {'Feb','Mar','Apr'};
remove(M,keySet);
keys(M)
ans = 1x1 cell array
    {'Jan'}

values(M)
ans = 1x1 cell array
    {[327.2000]}

Input Arguments

collapse all

Input Map object.

Keys of the key-value pairs to remove from the Map object, specified as a numeric scalar, character vector, string scalar, or cell array. To remove multiple key-value pairs, specify keySet as a cell array—even when you specify the keys as numeric scalars or strings.

Introduced in R2008b