Map是储存键值对的结构体。键是实数或字符向量,值是标量或非标量数组。
定义统一值
keySet = {'Jan','Feb','Mar','Apr'};
valueSet = [327.2 368.2 197.6 178.4];
M = containers.Map(keySet, valueSet);
定义非统一值
keySet = {'Li','Jones','Sanchez'};
testLi = [5.8 7.35];
testJones = [27 3.92 6.4 8.21];
testSanchez = 'C:\Tests\Sanchez.dat';
valueSet = {testLi,testJones,testSanchez};
M = containers.Map(keySet,valueSet,'UniformValues',false)
调用
M('Jan');
定义空映射
M = containers.Map('KeyType','char','ValueType','double');
M('Jan') = 327.2;
M('Feb') = 368.2;
显示键
keys(M)
显示值
values(M)
属性
- Count:键值对数量
- KeyType:键数据类型
- ValueType:值数据类型