Stateflow.State
State in chart, state, or box
Description
Use Stateflow.State
objects to describe an operating mode of a
reactive system. For more information, see Represent Operating Modes by Using States.
Creation
Description
Input Arguments
parent
— Parent for new state
Stateflow.Chart
object | Stateflow.State
object | Stateflow.Box
object
Parent for the new state, specified as a Stateflow® API object of one of these types:
Stateflow.State
Properties
Stateflow API objects have properties that correspond to the values you set in the Stateflow
Editor. To access or modify a property, use dot notation. To access or modify multiple
properties for multiple API objects, use the get
and
set
functions, respectively. For more information, see Modify Properties and Call Functions of Stateflow Objects.
Content
Name
— Name of state
""
(default) | string scalar | character vector
Name of the state, specified as a string scalar or character vector.
LabelString
— Label for state
"?"
(default) | string scalar | character vector
Label for the state, specified as a string scalar or character vector. For more information, see Specify Labels in States and Transitions Programmatically.
DuringAction
— State during
action
character vector
This property is read-only.
State during
action, specified as a character vector. The value
of this property depends on the LabelString
property for the
state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.
EntryAction
— State entry
action
character vector
This property is read-only.
State entry
action, specified as a character vector. The value
of this property depends on the LabelString
property for the
state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.
ExitAction
— State exit
action
character vector
This property is read-only.
State exit
action, specified as a character vector. The value
of this property depends on the LabelString
property for the
state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.
MooreAction
— State action in Moore chart
character vector
This property is read-only.
State action in a Moore chart, specified as a character vector. The value of this
property depends on the LabelString
property for the state. For
more information, see Specify Labels in States and Transitions Programmatically. This property is supported only in Moore
charts. For more information, see Design Guidelines for Moore Charts.
OnAction
— State on
actions
cell array of character vectors
This property is read-only.
State on
actions, specified as a cell array of character
vectors in the form
{'trigger1','action1',...,'triggerN','actionN'}
The value of this property depends on the LabelString
property for the state. For more information, see Specify Labels in States and Transitions Programmatically. This property is not supported in Moore charts.
IsExplicitlyCommented
— Whether to comment out state
false
or 0 (default) | true
or 1
Whether to comment out the state, specified as a numeric or logical 1
(true
) or 0 (false
). Setting this property to
true
is equivalent to right-clicking the state and selecting
Comment Out. For more information, see Comment Out Objects in a Stateflow Chart.
IsImplicitlyCommented
— Whether state is implicitly commented out
true
or 1 | false
or 0
This property is read-only.
Whether the state is implicitly commented out, specified as a numeric or logical 1
(true
) or 0 (false
). The state is implicitly
commented out when you explicitly comment out an object that contains it. If the state
is contained in an atomic subchart, this property is false
unless
the explicitly commented object is also contained in the atomic subchart.
IsCommented
— Whether state is commented out
true
or 1 | false
or 0
Since R2023a
This property is read-only.
Whether the state is commented out, specified as a numeric or logical 1
(true
) or 0 (false
). This property is
true
when either IsExplicitlyCommented
or
IsImplicitlyCommented
is true
.
CommentText
— Comment text
""
(default) | string scalar | character vector
Comment text added to the state, specified as a string scalar or character vector.
This property applies only when the IsExplicitlyCommented
property is true
. In the Stateflow Editor, when you point to the comment badge on the state, the text appears as a tooltip. When you
set the
IsExplicitlyCommented
property to
false
, the value of CommentText
reverts to
""
.
Graphical Appearance
Position
— Position and size of state
[0 0 90 60]
(default) | [left top width height]
Position and size of the state, specified as a four-element numeric vector of the
form [left top width height]
.
BadIntersection
— Whether state intersects a box, state, or function
true
or 1 | false
or 0
This property is read-only.
Whether the state graphically intersects a box, state, or function, specified as a
numeric or logical 1 (true
) or 0 (false
).
IsGrouped
— Whether state is a grouped state
false
or 0 (default) | true
or 1
Whether the state is a grouped state, specified as a numeric or logical 1
(true
) or 0 (false
). When you copy and paste a
grouped state, you copy not only the state but all of its contents. For more
information, see Copy and Paste by Grouping.
IsSubchart
— Whether state is a subchart
false
or 0 (default) | true
or 1
Whether the state is a subchart, specified as a numeric or logical 1
(true
) or 0 (false
).
ContentPreviewEnabled
— Whether to display preview of state contents
false
or 0 (default) | true
or 1
Whether to display a preview of the state contents, specified as a numeric or
logical 1 (true
) or 0 (false
). This property
applies only when the IsSubchart
property is
true
.
ArrowSize
— Size of incoming transition arrows
8
(default) | scalar
Size of incoming transition arrows, specified as a scalar.
FontSize
— Font size for state label
scalar
Font size for the state label, specified as a scalar. The
StateFont.Size
property of the chart that contains the state
sets the initial value of this property.
State Decomposition
Decomposition
— Decomposition of substates
"EXCLUSIVE_OR"
(default) | "PARALLEL_AND"
Decomposition of substates at the top level of containment in the state, specified
as "EXCLUSIVE_OR"
or "PARALLEL_AND"
. For more
information, see Specify Substate Decomposition.
Type
— Decomposition of sibling states
'AND'
| 'OR'
This property is read-only.
Decomposition of sibling states, specified as 'AND'
or
'OR'
. The state inherits this property from the
Decomposition
property of its parent state or chart.
ExecutionOrder
— Execution order in parallel (AND) decomposition
scalar
Execution order for the state in parallel (AND) decomposition, specified as an integer scalar. This property applies only when both of these conditions are satisfied:
The
Type
property of the state is"AND"
.The
UserSpecifiedStateTransitionExecutionOrder
property of the chart that contains the state istrue
.
Active State Output
HasOutputData
— Whether to create active state data output
false
or 0 (default) | true
or 1
Whether to create an active state data output port for the state, specified as a
numeric or logical 1 (true
) or 0 (false
). For
more information, see Monitor State Activity Through Active State Data.
OutputData
— Active state data object
Stateflow.Data
object
This property is read-only.
Active state data object for the state, specified as a Stateflow.Data
object. This property applies only when the
HasOutputData
property for the state is
true
.
OutputPortName
— Name of active state data object
string scalar | character vector
Name of the active state data object for the state, specified as a string scalar
or character vector. This property applies only when the
HasOutputData
property for the state is
true
.
OutputMonitoringMode
— Monitoring mode for active state output
"SelfActivity"
(default) | "ChildActivity"
| "LeafStateActivity"
Monitoring mode for the active state output data, specified as
"SelfActivity"
, "ChildActivity"
, or
"LeafStateActivity"
.
EnumTypeName
— Name of enumerated data type for active state data object
string scalar | character vector
Name of the enumerated data type for the active state data object for the state,
specified as a string scalar or character vector. This property applies only when the
OutputMonitoringMode
property for the state is
"ChildActivity"
or "LeafStateActivity"
. For
more information, see Enum Name.
DoNotAutogenerateEnum
— Whether to define enumerated data type manually
false
or 0 (default) | true
or 1
Whether to define the enumerated data type for the active state data output
manually, specified as a numeric or logical 1 (true
) or 0
(false
). This property applies only when the
OutputMonitoringMode
property for the state is
"ChildActivity"
or "LeafStateActivity"
. For
more information, see Define State Activity Enumeration Type.
Signal Logging and Test Point Monitoring
LoggingInfo
— Signal logging properties
Stateflow.SigLoggingInfo
object
Signal logging properties for the state, specified as a Stateflow.SigLoggingInfo
object
with these properties:
DataLogging
— Whether to enable signal logging, specified as a numeric or logical 1 (true
) or 0 (false
).DecimateData
— Whether to limit the amount of logged data, specified as a numeric or logical 1 (true
) or 0 (false
).Decimation
— Decimation interval, specified as an integer scalar. This property applies only when theDecimateData
property istrue
.LimitDataPoints
— Whether to limit the number of data points to log, specified as a numeric or logical 1 (true
) or 0 (false
).MaxPoints
— Maximum number of data points to log, specified as an integer scalar. This property applies only when theLimitDataPoints
property istrue
.NameMode
— Source of the signal name, specified as"SignalName"
or"Custom"
.LoggingName
— Custom signal name, specified as a string scalar or character vector. This property applies only when theNameMode
property is"Custom"
.
Signal logging saves the self activity of the state to the MATLAB® workspace during simulation. For more information, see Log Simulation Output for States and Data.
Example: state.LoggingInfo.DataLogging = true;
TestPoint
— Whether to set state as test point
false
or 0 (default) | true
or 1
Whether to set the state as a test point, specified as a numeric or logical 1
(true
) or 0 (false
). You can monitor
testpoints with a floating scope during simulation. You can also log test point values
to the MATLAB workspace. For more information, see Monitor Test Points in Stateflow Charts.
Debugging
Debug
— Debugger properties
Stateflow.StateDebug
object
Debugger properties for the state, specified as a Stateflow.StateDebug
object with
these properties:
OnEntry
— Whether to set theOn State Entry
breakpoint, specified as a numeric or logical 1 (true
) or 0 (false
).OnDuring
— Whether to set theDuring State
breakpoint, specified as a numeric or logical 1 (true
) or 0 (false
).OnExit
— Whether to set theOn State Exit
breakpoint, specified as a numeric or logical 1 (true
) or 0 (false
).
For more information, see Set Breakpoints to Debug Charts.
Example: state.Debug.Breakpoints.OnEntry = true;
Example: state.Debug.Breakpoints.OnDuring = true;
Example: state.Debug.Breakpoints.OnExit = true;
Code Generation
InlineOption
— Appearance in generated code
"Auto"
(default) | "Function"
| "Inline"
Appearance of the state functions in generated code, specified as one of these values:
"Auto"
— An internal calculation determines the appearance of state functions in generated code."Function"
— State functions are implemented as separate static functions."Inline"
— Calls to state functions are replaced by code as long as the function is not part of a recursion.
For more information, see Inline State Functions in Generated Code (Simulink Coder).
Hierarchy
Chart
— Chart that contains state
Stateflow.Chart
object
This property is read-only.
Chart that contains the state, specified as a Stateflow.Chart
object.
Subviewer
— Subviewer for state
Stateflow.Chart
object | Stateflow.State
object | Stateflow.Box
object | Stateflow.Function
object
This property is read-only.
Subviewer for the state, specified as a Stateflow.Chart
,
Stateflow.State
, or Stateflow.Box
object. The
subviewer is the chart or subchart where you can graphically view the state.
Machine
— Machine that contains state
Stateflow.Machine
object
This property is read-only.
Machine that contains the state, specified as a Stateflow.Machine
object.
Path
— Location of parent in model hierarchy
character vector
This property is read-only.
Location of the parent of the state in the model hierarchy, specified as a character vector.
Identification
Description
— Description
""
(default) | string scalar | character vector
Description for the state, specified as a string scalar or character vector.
Document
— Document link
""
(default) | string scalar | character vector
Document link for the state, specified as a string scalar or character vector.
Tag
— User-defined tag
[]
(default) | any data type
User-defined tag for the state, specified as data of any type.
SSIdNumber
— Session-independent identifier
scalar
This property is read-only.
Session-independent identifier, specified as an integer scalar. Use this property to distinguish the state from other objects in its parent chart.
Id
— Unique identifier
scalar
This property is read-only.
Unique identifier, specified as an integer scalar. Unlike
SSIdNumber
, the value of this property is reassigned every time
you start a new MATLAB session and may be recycled after an object is deleted.
Object Functions
find | Identify specified objects in hierarchy |
getChildren | Identify children of object |
getParent | Identify parent of object |
defaultTransitions | Identify default transitions in specified object |
innerTransitions | Identify inner transitions with specified source |
outerTransitions | Identify outgoing transitions with specified source |
sinkedTransitions | Identify transitions with specified destination |
sourcedTransitions | Identify transitions with specified source |
getReferences | Identify references to symbol name |
renameReferences | Rename symbol and update references to symbol name |
commentedBy | Identify objects that implicitly comment out a graphical object |
dialog | Open properties dialog box |
view | Display object in editing environment |
highlight | Highlight graphical object |
fitToView | Zoom in on graphical object |
Examples
Add State to Chart
Add a state in the chart ch
. Set its name to
A
.
state = Stateflow.State(ch);
state.Name = "A";
Enter Multiline Label in State
To enter a multiline label in the state state
, you
can:
Call the MATLAB function
sprintf
and use the escape sequence\n
to insert newline characters:str = sprintf("A\nen: action1();\ndu: action2();\nen,du: action3();"); sA.LabelString = str;
Enter a concatenated text expression that uses the function
newline
to create newline characters:str = "A" + newline + ... "en: action1();" + newline + ... "du: action2();" + newline + ... "en,du: action3();" sA.LabelString = str;
To extract the state name, entry
action, and
during
action specified by the state label, enter:
name = state.Name
name = 'A'
entry = state.EntryAction
entry = ' action1(); action3();'
during = state.DuringAction
during = ' action2(); action3();'
For more information, see Specify Labels in States and Transitions Programmatically.
Add Supertransition from Subchart
Create a supertransition that connects a junction inside a subchart to a junction outside the subchart.
Open the model and access the Stateflow.Chart
object for the chart.
open_system("sfSupertransitionAPIExample") ch = find(sfroot,"-isa","Stateflow.Chart");
Access the Stateflow.State
object for the subchart and the Stateflow.Junction
objects for the junctions.
st = find(ch,"-isa","Stateflow.State"); j1 = find(st,"-isa","Stateflow.Junction"); j2 = find(ch,"-isa","Stateflow.Junction","-depth",1);
Save the original position of the subchart to a temporary workspace variable subchartPosition
.
subchartPosition = st.Position;
Convert the subchart to a normal state by setting its IsSubchart
and IsGrouped
properties to false
.
st.IsSubchart = false; st.IsGrouped = false;
When you convert a subchart to a normal state, it may change size to display its contents.
Add a transition that connects junction j1
to junction j2
.
tr = Stateflow.Transition(ch); tr.Source = j1; tr.Destination = j2;
Revert the state to a subchart by setting its IsSubchart
property to true
. Restore the subchart to its original position.
st.IsSubchart = true; st.Position = subchartPosition;
The transition between the junctions is now a supertransition that crosses the boundary of the subchart.
Version History
Introduced before R2006aR2023a: New object functions and properties
Stateflow.State
objects have new object functions and properties:
The object function
getReferences
returns the locations where a chart refers to the name of a state.The object function
renameReferences
renames a state and updates all references to the state name in the chart.The object function
commentedBy
identifies the explicitly commented objects that cause a state to be commented out.The property
IsCommented
indicates whether a state is commented out. This property replaces the object functionisCommented
.
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)