In general, to use objects as indexes , define a subsindex for your class.
Note that against everything else in MATLAB, subsindex should return indexes with a null value.
classdef E < uint32 enumeration Left (1); Right (2); Neither (3); end methods function ind = subsindex(obj) ind = uint32(obj) - 1; end end end
Example:
>> x = 1:10; >> x(E.Right) ans = 2
Note that even without defining a subsindex method subsindex classes that inherit from the built-in type should work as indexes as usual (at least it worked that way in my version of R2013a).
If you want to work with container.Map, you must explicitly list the enum as uint32 . I think the containers.Map/subsref method does not use isa to check the type of indexing, instead use something like strcmp(class(obj),'..') , which explains the error message:
Error using containers.Map/subsref Specified key type does not match the type expected for this container.
source share