na_0031: 列挙型の既定値の定義
該当ガイドライン
Control Algorithm Modeling Guidelines - Using MATLAB®, Simulink®, and 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:
列挙型に既定値が明示的に定義されていない場合、記述される最初の列挙文字列が既定値として定義されるため、意図した結果にならない場合があります。
検証
モデル アドバイザー チェック: Check usage of enumerated values (Simulink Check)
最終更新
R2020a
参考
列挙データ型の定義 (Stateflow)
バージョン履歴
R2020a で導入