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

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

Edge Detection

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

Message Activity

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

State Activity

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

Data Type Conversion

castConvert numeric value to different numeric data type
booleanConvert numeric value to Boolean value
ascii2strConvert array of type uint8 to string
str2asciiConvert string to array of type uint8
str2doubleConvert string to double-precision value in Stateflow chart
stringConvert value to string in Stateflow chart
tostringConvert value to string
typeType of Stateflow data object

String Creation and Concatenation

blanksCharacter array of spaces
plusConcatenate strings in Stateflow chart
strcpyAssign string value
strcatConcatenate strings

Properties of String Data

isletterDetermine which characters are letters in Stateflow chart
isspaceDetermine which characters are spaces in Stateflow chart
isstringDetermine if input is string in Stateflow chart
strlenDetermine length of string
strlengthDetermine length of string in Stateflow chart

Find and Replace Substrings

containsDetermine if string contains substring in Stateflow chart
startsWithDetermine if string starts with substring in Stateflow chart
endsWithDetermine if string ends with substring in Stateflow chart
strfindFind substring within a string in Stateflow chart
extractAfterExtract substring after position in Stateflow chart
extractBeforeExtract substring before position in Stateflow chart
substrExtract substring from string
replaceFind and replace substrings in Stateflow chart
replaceBetweenReplace substrings between start and end points in Stateflow chart
strrepFind and replace substrings in Stateflow chart
eraseDelete substrings within strings in Stateflow chart
eraseBetweenDelete substring between start and end points in Stateflow chart
insertAfterInsert string after substring in Stateflow chart
insertBeforeInsert string before substring in Stateflow chart

Edit String Data

lowerConvert string to lowercase in Stateflow chart
upperConvert a string to uppercase in Stateflow chart
reverseReverse order of characters in strings in Stateflow chart
stripRemove leading and trailing characters from string in Stateflow chart
strtrimRemove leading and trailing white space from string in Stateflow chart

Compare String Data

matchesDetermine if two strings match in Stateflow chart
strcmpCompare strings in Stateflow chart (case sensitive)
strcmpiCompare strings in Stateflow chart (case insensitive)
strncmpCompare first N characters of strings in Stateflow chart (case sensitive)
strncmpiCompare first N characters of strings in Stateflow chart (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
everyExecute chart at regular intervals
durationTime during which condition is valid in Stateflow chart
elapsedTime since state became active
countNumber of chart executions during which condition is valid
temporalCountNumber of events, chart executions, or time since state became active

Interface with MATLAB Code

thisAccess chart data during simulation

Topics

Featured Examples