The problem is that you're using the default constructor for the containers.Map
class. From the help:
myMap = containers.Map() creates an empty object myMap that is an
instance of the MATLAB containers.Map class. The properties of myMap
are Count (set to 0), KeyType (set to 'char'), and ValueType (set to
'any').
In other words, you can only use strings as keys in this form. If you want to use arbitrary double precision values as keys, you need to specify the 'KeyType'
and 'ValueType'
in the constructor:
myMap = containers.Map('KeyType', kType, 'ValueType', vType) constructs
a Map object with no data that uses a key type of kType, and a value
type of vType. Valid values for kType are the strings: 'char',
'double', 'single', 'int32', 'uint32', 'int64', 'uint64'. Valid values
for vType are the strings: 'char', 'double', 'single', 'int8', 'uint8',
'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64', 'logical', or
'any'. The order of the key type and value type arguments is not
important, but both must be provided.
In your example:
a = containers.Map('KeyType','double','ValueType','any');
a(pi) = 3:14;
a(5) = 4:2:10;
Note, however, that a 'ValueType'
of 'double'
will not work for non-scalar values. Alternatively, you can specify your keys and values directly with cell arrays via the constructor and let it do the work of figuring out what types to use:
a = containers.Map({pi,5},{3:14 4:2:10});