5
我有一個枚舉:字符串枚舉
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