7
在MATLAB得到一个枚举的名字我定义枚举类型如何在MATLAB
classdef(Enumeration) Color < Simulink.IntEnumType
enumeration
RED(0),
GREEN(1),
BLUE(2),
end
end
我可以为它分配:
>> disp(x)
RED
:
>> x = Color.RED
x =
RED
我可以这样显示出来
或类似
>> x.display()
x =
RED
如何才能以字符串的形式访问该名称(“RED”)?
换句话说,我看着这样的事情:
s = x.toString()
或
s = tostring(x)
两者不工作。
注:因为我没有SIMULINK,我测试了上面使用了定义:'classdef(Enumeration)Color
Amro
2010-02-22 18:46:47
你测试了什么'str'实际上是?我现在不能测试它,但我认为这可能只是将枚举类型的*整数表达*转换为一个'char'(即'char(0)')。 – gnovice 2010-02-22 19:41:52
@gnovice:正如预期的那样返回'“RED” – Amro 2010-02-22 19:59:59