主要内容

na_0031:默认枚举值的定义

规范来源

控制算法建模规范 - 使用 MATLAB®、Simulink® 和 Stateflow®

子 ID 建议

  • NA-MAAB - a

  • JMAAB - a

MATLAB 版本

全部

规则

子 ID a

方法 getDefaultValue() 应用于显式定义枚举的默认值。

自定义参数

不适用

示例 - 正确

请参阅指定默认枚举值

classdef BasicColors < Simulink.IntEnumType
  enumeration
    Red(0)
    Yellow(1)
    Blue(2) 
  end
  methods (Static)
    function retVal = getDefaultValue()
      retVal = BasicColors.Blue;
    end
  end
end 
示例 - 不正确
classdef(Enumeration) BasicColors < Simulink.IntEnumType
  enumeration
    Red(0)
    Yellow(1)
    Blue(2) 
  end
end 

理由

子 ID a:

  • 当枚举类型没有显式定义的默认值时,描述的第一个枚举字符串将被定义为默认值,这可能不符合预期。

验证

模型顾问检查:检查枚举值的使用 (Simulink Check)

上次更改

R2020a

版本历史记录

在 R2020a 中推出