Main Content

Control Algorithm Execution Using Enumerated Signal

This example shows how to use a signal of an enumerated data type to control the execution of a block algorithm. For basic information about using enumerated data types in models, see Use Enumerated Data in Simulink Models.

Define Enumerated Type

Copy the enumerated type definition ex_SwitchCase_MyColors into a script file in your current folder.

classdef ex_SwitchCase_MyColors < Simulink.IntEnumType

Alternatively, you can use the function Simulink.defineIntEnumType to define the type.


Explore Example Model

Open the example model ex_enum_switch_case.


Open the Enumerated Constant block dialog box. The constant output value is ex_SwitchCase_MyColors.Blue.

Open the Switch Case block dialog box. The Case conditions box is specified as a cell array containing three of the four possible enumeration members. The block has four outputs corresponding to the three specified enumeration members and a default case.

Open the Switch Case Action Subsystem blocks. The subsystems each contain a Constant block that uses a different constant value.

Control Execution During Simulation

Simulate the model. The Display block shows the value 5, which corresponds to the case ex_SwitchCase_MyColors.Blue.

In the Enumerated Constant block dialog box, specify Value as ex_SwitchCase_MyColors.Red and click Apply. The Display block shows 19.

Specify Value as ex_SwitchCase_MyColors.Mauve and click Apply. The Display block shows 3, which corresponds to the default case.

See Also



Related Topics