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

Chart Implement control logic with finite state machine
State Transition Table Represent modal logic in tabular format
Truth Table Represent logical decision-making behavior with conditions, decisions, and actions

Stateflow Syntax

expand all

Change Detection

change Generate implicit event when data changes value
hasChanged Detect change in data since last time step
hasChangedFrom Detect change in data from specified value
hasChangedTo Detect change in data to specified value

Edge Detection

crossing Detect rising or falling edge in data since last time step
falling Detect falling edge in data since last time step
rising Detect rising edge in data since last time step

Message Activity

discard Discard message
forward Forward message
isvalid Determine if message is valid
length Determine length of message queue
receive Extract message from queue
send Broadcast message or event

State Activity

enter Generate implicit event when state becomes active
exit Generate implicit event when state becomes inactive
in Check state activity inStateflow

Create, Concatenate, and Convert String Data

ascii2str Convert array of typeuint8to string
blanks Create a character array of blanks
double Convert string to double precision value
isletter Determine which characters are letters
isspace 确定哪些字符空格字符
str2ascii Convert string to array of typeuint8
str2double Convert string to double-precision value
strcat Concatenate strings
strcmp Compare strings
string Create a string
tostring Convert numeric value to string

Determine Types and Properties String Data

isletter Determine which characters are letters
isspace 确定哪些字符空格字符
isstring Determine if input is string
strlen Determine length of string
strlength Length of string

Find and Replace String Data

contains Determine if pattern is in a string
endsWith Determine if strings end with pattern
matches Determine if pattern matches string
replace Find and replace one or more substring
replaceBetween Replace substrings between start and end points
startsWith Determine if strings start with pattern
strfind Find strings within other strings
strrep Find and replace substrings

编辑字符串数据

erase Delete substrings within strings
eraseBetween Delete substring between start and end points
extractAfter Extract substring after specified positions
extractBefore Extract substring before specified positions
insertAfter Insert string after specified substring
insertBefore Insert string before specified substring
lower Convert string to lowercase
plus Append strings
reverse Reverse order of characters in strings
strcpy Assign string value
strip Remove leading and trailing characters from string
strtrim Remove leading and trailing white space from a string
substr Extract substring from string
Convert a string to uppercase

Compare String Data

matches Determine if pattern matches string
strcmp Compare strings
strcmpi Compare strings (case insensitive)
strncmp Compare firstncharacters of strings (case sensitive)
strncmpi Compare firstncharacters of strings (case insensitive)

Temporal Logic

after Execute chart after event broadcast or specified time
at Execute chart at event broadcast or specified time
before Execute chart before event broadcast or specified time
count Chart executions during which condition is valid
duration Time during which condition is valid
elapsed Time since state became active
every Execute chart at regular intervals
temporalCount Number of events, chart executions, or time since state became active

Topics

Related Information