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.

Blocks

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

Edge Detection

crossingDetect rising or falling edge in data since last time step
fallingDetect falling edge in data since last time step
risingDetect rising edge in data since last time step

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

Create, Concatenate, and Convert String Data

ascii2strConvert array of type uint8 to string
blanksCreate a character array of blanks
doubleConvert string to double precision value
isletterDetermine which characters are letters
isspaceDetermine which characters are space characters
str2asciiConvert string to array of type uint8
str2doubleConvert string to double-precision value
strcatConcatenate strings
strcmpCompare strings
stringCreate a string
tostringConvert numeric value to string

Determine Types and Properties String Data

isletterDetermine which characters are letters
isspaceDetermine which characters are space characters
isstringDetermine if input is string
strlenDetermine length of string
strlengthLength of string

Find and Replace String Data

containsDetermine if pattern is in a string
endsWithDetermine if strings end with pattern
matchesDetermine if pattern matches string
replaceFind and replace one or more substring
replaceBetweenReplace substrings between start and end points
startsWithDetermine if strings start with pattern
strfindFind strings within other strings
strrepFind and replace substrings

Edit String Data

eraseDelete substrings within strings
eraseBetweenDelete substring between start and end points
extractAfterExtract substring after specified positions
extractBeforeExtract substring before specified positions
insertAfterInsert string after specified substring
insertBeforeInsert string before specified substring
lowerConvert string to lowercase
plusAppend strings
reverseReverse order of characters in strings
strcpyAssign string value
stripRemove leading and trailing characters from string
strtrimRemove leading and trailing white space from a string
substrExtract substring from string
upperConvert a string to uppercase

Compare String Data

matchesDetermine if pattern matches string
strcmpCompare strings
strcmpiCompare strings (case insensitive)
strncmpCompare first n characters of strings (case sensitive)
strncmpiCompare first n characters of strings (case insensitive)

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

Topics

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 and Expression Values

Define chart behavior when data and expressions 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