Main Content

Syntax for States and Transitions

Express chart behavior by using actions and conditions

Control the execution of your Stateflow® chart by specifying when transitions between states occur and when actions are executed. Synchronize state execution by broadcasting events. Detect changes in data values and check which states are active during chart execution.


expand all

ChartImplement control logic with finite state machine
State Transition TableRepresent modal logic in tabular format
Truth TableRepresent logical decision-making behavior with conditions, decisions, and actions

Stateflow Syntax

expand all

Change Detection

changeGenerate implicit event when data changes value
hasChangedDetect change in data since last time step
hasChangedFromDetect change in data from specified value
hasChangedToDetect change in data to specified value

Message Activity

discardDiscard message
forwardForward message
isvalidDetermine if message is valid
lengthDetermine length of message queue
receiveExtract message from queue
sendBroadcast message or event

State Activity

enterGenerate implicit event when state becomes active
exitGenerate implicit event when state becomes inactive
inCheck state activity in Stateflow

String Manipulation

ascii2strConvert array of type uint8 to string
str2asciiConvert string to array of type uint8
str2doubleConvert string to double precision value
strcatConcatenate strings
strcmpCompare strings
strcpyAssign string value
strlenDetermine length of string
substrExtract substring from string
tostringConvert numeric value to string

Temporal Logic

afterExecute chart after event broadcast or specified time
atExecute chart at event broadcast or specified time
beforeExecute chart before event broadcast or specified time
countChart executions during which condition is valid
durationTime during which condition is valid
elapsedTime since state became active
everyExecute chart at regular intervals
temporalCountNumber of events, chart executions, or time since state became active


Guidelines for Naming Stateflow Objects

Reserved keywords, name length restrictions, and naming limitations.

Eliminate Redundant Code by Combining State Actions

Combine entry, during, and exit actions in a state.

Control Function-Call Subsystems by Using bind Actions

Bind a function-call output event to the activity of a state.

Combine Transitions and Junctions to Create Branching Paths

Create decision points in transition paths.

Supported Operations for Chart Data

Perform mathematical computations in Stateflow charts.

Supported Symbols in Actions

Special symbols available for state and transition actions.

Call Extrinsic MATLAB Functions in Stateflow Charts

Access MATLAB® functions that are not supported for code generation.

Access MATLAB Functions and Workspace Data in C Charts

Call built-in MATLAB functions by using the ml operator.

Call C Library Functions in C Charts

Access C functions in state and transition labels.

Check State Activity by Using the in Operator

Determine if a state is active during chart execution.

Detect Changes in Data Values

Define chart behavior when data change value between time steps.

Control Chart Execution by Using Temporal Logic

Use event-based and absolute-time temporal logic operators.

Control Chart Behavior by Using Implicit Events

Trigger chart actions by changes in data values and state activity.

Control Oscillations by Using the duration Operator

Simplify debouncing logic in charts that have transient signals.

Related Information

Featured Examples