2
这里,示例代码:Matlab的使用多个containers.Map引发指数超过矩阵尺寸误差
A类:
classdef classA
properties
mapOfB
end
methods
function self = classA(names)
self.mapOfB = containers.Map();
for i = 1:numel(names)
self.mapOfB(names{i}) = classB(names);
end
end
end
end
B类:
classdef classB
properties
mapTest
end
methods
function self = classB(names)
self.mapTest = containers.Map();
for i = 1:numel(names)
self.mapTest(names{i}) = rand(1,3);
end
end
end
end
主脚本:
names = {'one', 'two', 'three', 'four'};
a = classA(names);
a.mapOfB
a.mapOfB.keys
a.mapOfB('one')
a.mapOfB('one').mapTest
a.mapOfB('one').mapTest.keys
a.mapOfB('one').mapTest('one')
控制台输出放:
a.mapOfB('one').mapTest.keys
ans =
'four' 'one' 'three' 'two'
a.mapOfB('one').mapTest('one')
Error using subsref
Index exceeds matrix dimensions.
我不明白为什么有一个指标超过矩阵尺寸错误,当我在地图调用的地图项目。这是一个Matlab的限制?
不知道确切的答案,但我想这是某种两个相关怎样[的subsref](http://www.mathworks.com.au/help/matlab/ref/subsref .html)和[索引](http://www.mathworks.com.au/help/matlab/matlab_oop/indexed-reference-and-assignment.html)如何在matlab中工作。 – Marcin