Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

remove (Map) - Remove key-value pairs from containers.Map

Syntax

remove(M, keys)

Description

remove(M, keys) erases all specified keys, and the values associated with them, from Map object M.keys can be a scalar key or a cell array of keys.

Using remove changes the count of the elements in the map.

Read more about Map Containers in the MATLAB Programming Fundamentals documentation.

Examples

Create a Map object containing the names of several US states and the capital city of each:

US_Capitals = containers.Map( ...
{'Arizona', 'Nebraska', 'Nevada', 'New York', ...
 'Georgia', 'Alaska', 'Vermont', 'Oregon'}, ...
{'Phoenix', 'Lincoln', 'Carson City', 'Albany', ...
 'Atlanta', 'Juneau', 'Montpelier', 'Salem'});

After checking how many keys there are in the US_Capitals map, remove the key-value pair with key name Oregon from it:

US_Capitals.Count
ans =
    8

remove(US_Capitals, 'Oregon');

US_Capitals.Count
ans =
    7

Remove three more key-value pairs from the map:

remove(US_Capitals, {'Nebraska', 'Nevada', 'New York'});
US_Capitals.Count
ans =
    4

See Also

containers.Map, keys(Map), values(Map), size(Map), length(Map)isKey(Map),handle

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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