remove - Delete key-value pairs from Map object - MATLAB (original) (raw)
Delete key-value pairs from Map
object
Syntax
Description
Note
dictionary is recommended overcontainers.Map
because it accepts more data types as keys and values and provides better performance. (since R2022b)
remove([M](#d126e1560240),[keySet](#d126e1560265))
deletes the specified keys, and the values associated with them, from the inputMap
object.
Examples
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
ans=1×3 cell array {[437]} {[1089]} {[2362]}
ans = 1×3 cell {'Li, N.'} {'Jones, R.'} {'Sanchez, C.'}
Remove a key-value pair. Display the updated keys and values.
ans=1×2 cell array {[437]} {[1089]}
ans = 1×2 cell {'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 = 1×4 cell {'Apr'} {'Feb'} {'Jan'} {'Mar'}
ans=1×4 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 = 1×1 cell array {'Jan'}
ans = 1×1 cell array {[327.2000]}
Input Arguments
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, specifykeySet
as a cell array—even when you specify the keys as numeric scalars or strings.
Version History
Introduced in R2008b