na_0031: Definition of default enumerated value
Sub ID Recommendations
NA-MAAB — a
JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Method getDefaultValue()
shall be used to explicitly define the
default value of an enumeration.
Not Applicable
See Specify a Default Enumerated Value
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
Rationale
Sub ID a:
When an enumerated type does not have a clearly defined a default value, the first enumeration string that is described will be defined as the default, which may not be as intended.
Verification
Model Advisor check: Check usage of enumerated values (Simulink Check)
Last Changed
R2020a
See Also
JMAAB guideline na_0031, which is available in Control Algorithm Modeling Guidelines Using MATLAB, Simulink, and Stateflow on the MathWorks® website.
Define Enumerated Data Types (Stateflow)
Version History
Introduced in R2020a