Instantiate Enumerated Data in MATLAB Function Blocks

To instantiate an enumerated type in a MATLAB Function block, use dot notation to specify ClassName.EnumName. For example, the following MATLAB® function checkState instantiates the enumerated types switchmode and led from Control an LED Display. The dot notation appears highlighted in the code.

function led = checkState(state)
%#codegen

if state == switchmode.ON
    led = led.GREEN;
else
    led = led.RED;
end
Was this topic helpful?