我有一个枚举器:
classdef Commands
    properties
        commandString;
        readonly;
    end
    methods
        function obj = Commands(commandString, readonly)
            obj.commandString = commandString;
            obj.readonly= readonly;
        end
    end
    enumeration
        PositionMode('p', false)
        TravelDistance('s', false)
    end
end
我有一个字符串:
currentCommand = 'PositionMode';
我希望能够返回:
Commands.PositionMode
有没有比这更好的解决方案
methods(Static)
    function obj = str2Command(string)
        obj = eval(['Commands.' string]);
    end
end