Main Content

length

Number of key-value pairs in Map object

Description

Note

dictionary is recommended over containers.Map because it accepts more data types as keys and values and provides better performance. (since R2022b)

L = length(M) returns the number of key-value pairs in the input Map object. length(M) is equivalent to size(M,1) and to the property M.Count.

example

Examples

collapse all

Create a Map object.

months = {'Jan','Feb','Mar','Apr'};
rainfall = [327.2 368.2 197.6 178.4];
M = containers.Map(months,rainfall)
M = 
  Map with properties:

        Count: 4
      KeyType: char
    ValueType: double

Return the number of key-value pairs that it contains.

L = length(M)
L = 
4

Input Arguments

collapse all

Input Map object.

Version History

Introduced in R2008b