remove
Delete key-value pairs from Map
object
Syntax
Description
Examples
Remove Key-Value Pair
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=1×3 cell array
{[437]} {[1089]} {[2362]}
values(M)
ans = 1x3 cell
{'Li, N.'} {'Jones, R.'} {'Sanchez, C.'}
Remove a key-value pair. Display the updated keys and values.
remove(M,2362); keys(M)
ans=1×2 cell array
{[437]} {[1089]}
values(M)
ans = 1x2 cell
{'Li, N.'} {'Jones, R.'}
Remove Multiple Key-Value Pairs
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
{'Apr'} {'Feb'} {'Jan'} {'Mar'}
values(M)
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 = 1x1 cell array
{'Jan'}
values(M)
ans = 1x1 cell array
{[327.2000]}
Input Arguments
M
— Input Map
object
Map
object
Input Map
object.
keySet
— Keys of key-value pairs to remove
numeric scalar | character vector | string scalar | cell array
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.
Version History
Introduced in R2008b
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)