Documentation Center

  • Trial Software
  • Product Updates

Operations on Enumerated Data for Code Generation

To generate efficient standalone code for enumerated data, you are restricted to the following operations. The examples are based on the definitions of the enumeration type LEDcolor described in Class Definition: LEDcolor.

Assignment Operator, =

Example

Result

xon = LEDcolor.GREEN
xoff = LEDcolor.RED
xon = 

    GREEN
xoff = 

    RED

Relational Operators, < > <= >= == ~=

Example

Result

xon == xoff
ans =

     0
xon <= xoff
ans =

     1
xon > xoff
ans =

     0

Cast Operation

Example

Result

double(LEDcolor.RED)
ans =

     2
z = 2
y = LEDcolor(z)
z =

     2


y = 

    RED

Indexing Operation

Example

Result

m = [1 2]
n = LEDcolor(m)
p = n(LEDcolor.GREEN)
m =

     1     2


n = 

    GREEN    RED  


p = 

    GREEN

Control Flow Statements: if, switch, while

StatementExampleExecutable Example

if

if state == sysMode.ON
    led = LEDcolor.GREEN;
else
    led = LEDcolor.RED;
end

if Statement with Enumerated Data Types

switch

switch button
    case VCRButton.Stop
        state = VCRState.Stop;
    case VCRButton.PlayOrPause
        state = VCRState.Play;
    case VCRButton.Next
        state = VCRState.Forward;
    case VCRButton.Previous
        state = VCRState.Rewind;
    otherwise
         state = VCRState.Stop;
end

switch Statement with Enumerated Data Types

while

while state ~= State.Ready
    switch state
        case State.Standby
            initialize();
            state = State.Boot;
        case State.Boot
            boot();
            state = State.Ready;
    end
end

while Statement with Enumerated Data Types

Was this topic helpful?