MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

mapObj = containers.Map({key1, key2, ...}, {val1, val2, ...});


For those keys and values that are character vectors, be sure that you specify them
enclosed within single quotation marks. For example, when constructing a Map that has
character vectors as keys, use


mapObj = containers.Map(...
{'keystr1', 'keystr2', ...}, {val1, val2, ...});


As an example of constructing an initialized Map object, create a new Map for the
following key/value pairs taken from the monthly rainfall map shown earlier in this
section.


327.2
368.2
197.6
178.4
100.0
69.9
32.3
37.3
19.0
37.0
73.2
110.9
1551.0

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Annual

KEYS VALUES


k = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ...
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Annual'};


v = {327.2, 368.2, 197.6, 178.4, 100.0, 69.9, ...
32.3, 37.3, 19.0, 37.0, 73.2, 110.9, 1551.0};


rainfallMap = containers.Map(k, v)


rainfallMap =


Map with properties:


Create Map Object
Free download pdf