Reputation: 90
Here a sample code:
Class 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
Class 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
main script:
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')
console output:
a.mapOfB('one').mapTest.keys
ans =
'four' 'one' 'three' 'two'
a.mapOfB('one').mapTest('one')
Error using subsref
Index exceeds matrix dimensions.
I don't understand why there is an index exceeds matrix dimensions error when I call a map item in a map. It is a Matlab limitation ?
Upvotes: 2
Views: 323
Reputation: 785
This line, which is totally equivalent to "a.mapOfB('one').mapTest('one')", does not raise the error
builtin('_paren', a.mapOfB('one').mapTest, 'one')
Therefore it's not a "real" error, but a limitation on MATLAB's syntax or implementation of containers.Map's subsref() operator.
See also this popular question
Upvotes: 1