帮我初始化一个containers.Map

时间:2011-07-15 05:11:50

标签: matlab

M = containers.Map('KeyType','double')

而不是给我一张带有double类型键的地图,它给了我一张地图,他的一个键(字符串'KeyType')值为'double'

-_- 我做错了什么?

3 个答案:

答案 0 :(得分:4)

您还必须指定值类型;所以你需要写M = containers.Map('KeyType', 'double', 'ValueType', whatever)

答案 1 :(得分:1)

请注意:containers.Map()构造函数需要同时指定的原因是,否则containers.Map(keys,values)构造函数会出现歧义。

答案 2 :(得分:0)

>> f=containers.Map('KeyType','double','ValueType','char')
f = 
  Map with properties:
        Count: 0
      KeyType: double
    ValueType: char
>> f(3)='Hello'
f = 
  Map with properties:
        Count: 1
      KeyType: double
    ValueType: charf=containers.Map('KeyType','char','ValueType','double')

请注意,您也可以将其初始化为:

f=containers.Map({3,4},{'a','foo'})
f = 
  Map with properties:
        Count: 2
      KeyType: double
    ValueType: char