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
hasChangedFromDetect change in data from specified value
hasChangedToDetect change in data to specified value
changeGenerate implicit event when data changes 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

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

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
stringConvert value to string
tostringConvert value to string
typeType of Stateflow data object

String Creation and Concatenation

blanksCharacter array of spaces
plusConcatenate strings
strcpyAssign string value
strcatConcatenate strings

Properties of String Data

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

Find and Replace Substrings

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

Edit String Data

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

Compare String Data

matchesDetermine if two strings match
strcmpCompare strings (case sensitive)
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
everyExecute chart at regular intervals
durationTime during which condition is valid
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