Skip to Main Content Skip to Search
Product Documentation

Operations on Enumerated Data Allowed 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

Using the if Statement on 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

Using the switch Statement on 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

Using the while Statement on Enumerated Data Types

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS