Using Simulink.IntEnumType in the switch case block.

18 次查看(过去 30 天)
Attempting to use an enumeration in a switch case block. Per the block instructions I enter the "enumeration('enumclass')" in the block mask input, but it raises this error. I'm using the BasicColors from the demo, and the enumeration function works when ran from the command window.
Can anyone tell me what I'm missing?
classdef BasicColors < Simulink.IntEnumType enumeration Red(0) Yellow(1) Green(2) end end
Thanks!

回答(1 个)

Chaitali Gondhalekar
I understand that you want to use Enumerated Data Type with Switch Case block in Simulink.
You can specify the "Case conditions" in the switch case block mask as a cell array.
For Example, {BasicColors.Red, BasicColors.Yellow, BasicColors.Blue}
This case condition implies that port 1 is run when the input is "BasicColors.Red" and port 2 is run when the input is "BasicColors.Yellow" and port 3 is run when the input is "BasicColors.Blue".
The attached folder "enumTestTS" contains a Simulink model file "enum_ex_TS" that uses enumerated data type "BasicColors" with Switch Case block. The enumerated data type is defined in class file "BasicColors.m".
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by