size

Class: containers.Map
Package: containers

Size of containers.Map object

Syntax

dim = size(mapObj,1)
dimVector = size(mapObj)
[dim1,dim2,...,dimN] = size(mapObj)

Description

dim = size(mapObj,1) returns a scalar numeric value that indicates the number of key-value pairs in mapObj. If you call size with a numeric second input argument other than 1, the size method returns the scalar numeric value 1.

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

[dim1,dim2,...,dimN] = size(mapObj) returns [k,1,...,1].

Input Arguments

mapObj

Object of class containers.Map.

Output Arguments

dim

Scalar numeric value that indicates the number of key-value pairs in mapObj.

dimVector

Two-element numeric vector [k,1], where k is the number of key-value pairs in mapObj.

[dim1,dim2,...,dimN]

Numeric scalar values. Variable dim1 equals k, where k is the number of key-value pairs in mapObj. All other outputs equal 1.

Examples

Determine the Size of a Map

Construct a map and find the number of key-value pairs:

myKeys = {'a','b','c'};
myValues = [1,2,3];
mapObj = containers.Map(myKeys,myValues);
dim = size(mapObj,1)

This code returns a scalar numeric value:

dim =
     3

If you do not specify a second input argument,

dimVector = size(mapObj)

then the size method returns a vector:

dimVector =
     3     1
Was this topic helpful?