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.

Custom Parameter

Not Applicable

Example — Correct

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 

Example — Incorrect

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

Introduced in R2020a