Is there a native Simulink feature to trigger an error/warning when overflow from an 'enum' class instance occurs?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 29 Okt. 2020
Beantwortet: MathWorks Support Team
am 29 Okt. 2020
I have created an enum class (see below) which inherits from uint8 and it seems that there is no overflow error/warning from Simulink when loading testEnumClass.varC as an enumerated constant in Simulink.
classdef testEnumClass < uint8
enumeration
varA(1)
varB(2)
varC(1000)
end
end
Is there a native Simulink feature to trigger an error/warning, when there is such overflow, so that I can catch the wrong enum definitions in my model?
Akzeptierte Antwort
MathWorks Support Team
am 29 Okt. 2020
You can rewrite the enum definition using Simulink.defineIntEnumType, after which Simulink will raise an error if a value overflows.
The new enum definition can look like the following:
Simulink.defineIntEnumType('testEnumClass', ...
{'varA', 'varB', 'varC'}, ...
[1;2;1000], ...
'Description', 'Example', ...
'DefaultValue', 'varA', ...
'StorageType', 'uint8');
This produces the error: Underlying numeric values do not fit into the specified StorageType when loading testEnumClass.varC as an enumerated constant.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!