Main Content

size

Size of Map object

Description

example

Note

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

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

szdim = size(M,dim) returns the length of dimension dim. Since a Map object stores data as an n-by-1 set of key-value pairs, size returns 1 when dim > 1.

example

sz = size(M) returns a two-element vector [n 1], where n is the number of key-value pairs in M.

[sz1,sz2,...,szL] = size(M) returns [n,1,...,1].

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.

n = size(M,1)
n = 4

Return the number of pairs as a vector.

sz = size(M)
sz = 1×2

     4     1

Input Arguments

collapse all

Input Map object.

Queried dimension, specified as a positive numeric scalar.

Version History

Introduced in R2008b