Stateflow.Chart
Graphical representation of a finite state machine
Description
Use a Stateflow.Chart
object to create a graphical representation
of a finite state machine based on a state transition diagram. In a Chart block, states and transitions form the basic building blocks of a sequential
logic system. States correspond to operating modes and transitions represent pathways between
states. For more information, see Model Finite State Machines by Using Stateflow Charts and Create Charts by Using the Stateflow API.
Creation
To create a Stateflow.Chart
object, call the function sfnew
. For example, to create an empty chart in a new Simulink® model called myModel
, enter:
sfnew myModel
Alternatively, you can add a new chart to an existing model by using the function
add_block
(Simulink):
add_block("sflib/Chart","myModel/Chart")
Then, to access the Stateflow.Chart
object, call the find
function for the Simulink.Root
object:
chart = find(sfroot,"-isa","Stateflow.Chart", ... Path="myModel/Chart");
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 chart
"Chart"
(default) | string scalar | character vector
Name of the chart, specified as a string scalar or character vector.
ActionLanguage
— Action language
"MATLAB"
(default) | "C"
Action language used to program the chart, specified as
"MATLAB"
or "C"
. For more information, see
Differences Between MATLAB and C as Action Language Syntax.
StateMachineType
— State machine semantics
"Classic"
(default) | "Mealy"
| "Moore"
State machine semantics implemented by the chart, specified as
"Classic"
, "Mealy"
, or
"Moore"
. For more information, see Overview of Mealy and Moore Machines.
SupportVariableSizing
— Whether chart supports variable-size data
true
or 1 (default) | false
or 0
Whether the chart supports variable-size data, specified as a numeric or logical 1
(true
) or 0 (false
). For more information, see
Declare Variable-Size Data in Stateflow Charts.
TreatDimensionOfLengthOneAsFixedSize
— Whether chart treats output data with dimension of length 1 as fixed size
true
or 1
(default) | false
or 0
Since R2023a
Whether the chart treats output data with a dimension of length 1 as fixed size,
specified as a numeric or logical 0
(false
) or
1
(true
). When this property is
true
, the chart treats output data that have at least one
dimension of length 1 as fixed size, regardless of whether you specify the data as
having variable size. When this property is false
, the chart treats
output data as variable size if you specify the data as having variable size.
State Decomposition
Decomposition
— Decomposition of substates
"EXCLUSIVE_OR"
(default) | "PARALLEL_AND"
Decomposition of substates at the top level of containment in the chart, specified
as "EXCLUSIVE_OR"
or "PARALLEL_AND"
. For more
information, see Define Exclusive and Parallel Modes by Using State Decomposition.
Chart Initialization
ExecuteAtInitialization
— Whether to initialize state configuration
false
or 0 (default) | true
or 1
Whether to activate the chart with the start of simulation, specified as a numeric
or logical 1 (true
) or 0 (false
). For more
information, see Execution of a Chart at Initialization.
StatesWhenEnabling
— Behavior of states when event reenables chart
""
(default) | "held"
| "reset"
Behavior of the states when a function-call input event reenables the chart, specified as one of these values:
""
— The chart does not contain function-call input events."held"
— The chart maintains the most recent values of the states."reset"
— The chart reverts to the initial conditions of the states.
For more information, see Control States in Charts Enabled by Function-Call Input Events.
InitializeOutput
— Whether to initialize output data
false
or 0 (default) | true
or 1
Whether to initialize the output data every time the chart wakes up, specified as
a numeric or logical 1 (true
) or 0 (false
). For
more information, see Initialize outputs every time chart wakes up.
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 chart, 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 chart, specified as a Stateflow.Data
object. This property applies only when the
HasOutputData
property for the chart is
true
.
OutputPortName
— Name of active state data object
string scalar | character vector
Name of the active state data object for the chart, specified as a string scalar
or character vector. This property applies only when the
HasOutputData
property for the chart is
true
.
OutputMonitoringMode
— Monitoring mode for active state output
"ChildActivity"
(default) | "LeafStateActivity"
Monitoring mode for the active state output data, specified as
"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 chart, specified as a string scalar or character vector. 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
). For more information, see Define State Activity Enumeration Type.
Discrete and Continuous-Time Semantics
ChartUpdate
— Activation method for chart
"INHERITED"
(default) | "CONTINUOUS"
| "DISCRETE"
Activation method for the chart, specified as "CONTINUOUS"
,
"DISCRETE"
, or "INHERITED"
.
SampleTime
— Sample time for activating chart
"-1"
(default) | string scalar | character vector
Sample time for activating the chart, specified as a string scalar or character
vector. This property applies only when the ChartUpdate
property
for the chart is "DISCRETE"
.
EnableZeroCrossings
— Whether to enable zero-crossing detection
true
or 1 (default) | false
or 0
Whether to enable zero-crossing detection on state transitions in the chart,
specified as a numeric or logical 1 (true
) or 0
(false
). This property applies only when the
ChartUpdate
property for the chart is set to
"CONTINUOUS"
. For more information, see Disable Zero-Crossing Detection.
VariantActivationTime
— Which block variants Stateflow analyzes
update diagram analyze all choices
(default) | code compile
Which block variants Stateflow analyzes during simulation and code generation, specified as one of these values:
update diagram analyze all choices
— Stateflow analyzes both active and inactive choices for incompatibilities in signal attributes and generates code only for the active choice.code compile
— Stateflow analyzes both active and inactive choices of variant transitions and generates code for both the active and inactive choices. The choices are enclosed in C preprocessor conditional statements #if and #endif that are conditionally compiled when you compile the generated code.
Super Step Semantics
EnableNonTerminalStates
— Whether to enable super step semantics
false
or 0 (default) | true
or 1
Whether to enable super step semantics for the chart, specified as a numeric or
logical 1 (true
) or 0 (false
). For more
information, see Super Step Semantics.
NonTerminalMaxCounts
— Maximum number of transitions in one super step
1000
(default) | scalar
Maximum number of transitions the chart can take in one super step, specified as
an integer scalar. This property applies only when the
EnableNonTerminalStates
property for the chart is
true
.
NonTerminalUnstableBehavior
— Behavior if super step exceeds maximum number of transitions
"Proceed"
(default) | "Throw Error"
Behavior if a super step for the chart exceeds the maximum number of transitions
specified in the NonTerminalMaxCounts
property before reaching a
stable state, specified as one of these values:
"Proceed"
— The chart goes to sleep with the last active state configuration."Throw Error"
— The chart generates an error.
This property applies only when the
EnableNonTerminalStates
property for the chart is
true
.
Exported Functions
ExportChartFunctions
— Whether to export chart-level functions
false
or 0 (default) | true
or 1
Whether to export chart-level functions to other blocks in the Simulink model, specified as a numeric or logical 1 (true
) or
0 (false
). For more information, see Export Stateflow Functions for Reuse.
AllowGlobalAccessToExportedFunctions
— Whether exported functions are globally visible
false
or 0 (default) | true
or 1
Whether exported functions from the chart are globally visible in the Simulink model, specified as a numeric or logical 1 (true
) or
0 (false
). When this property is enabled, blocks throughout the
model can call functions exported from the chart without using qualified notation.
This property applies only when the ExportChartFunctions
property
for the chart is true
.
Integer and Fixed-Point Data
SaturateOnIntegerOverflow
— Whether data saturates on integer overflow
true
or 1 (default) | false
or 0
Whether the data in the chart saturates on integer overflow, specified as a
numeric or logical 1 (true
) or 0 (false
). When
this property is disabled, the data in the chart wraps on integer overflow. For more
information, see Handle Integer and Enumeration Overflow for Chart Data.
TreatAsFi
— Inherited Simulink signals to treat as fi
objects
"Fixed-point"
(default) | "Fixed-point & Integer"
Inherited Simulink signals to treat as Fixed-Point Designer™
fi
objects, specified as one of these values:
"Fixed-point"
— The chart treats all fixed-point inputs asfi
objects."Fixed-point & Integer"
— The chart treats all fixed-point and integer inputs asfi
objects.
This property applies only to charts that use MATLAB® as the action language.
EmlDefaultFimath
— Default fimath
properties
"Same as MATLAB Default"
(default) | "Other:UserSpecified"
Default fimath
properties for the chart, specified as one of
these values:
"Same as MATLAB Default"
— Use the samefimath
properties as the current defaultfimath
object."Other:UserSpecified"
— Use theInputFimath
property to specify the defaultfimath
object.
This property applies only when the
ActionLanguage
property of the chart is
"MATLAB"
.
InputFimath
— Default fimath
object
string scalar | character vector
Default fimath
object, specified as a string scalar or character
vector. When the EmlDefaultFimath
property for the chart is
"Other:UserSpecified"
, you can use this property to:
Enter an expression that constructs a
fimath
object.Enter the variable name for a
fimath
object in the MATLAB or model workspace.
This property applies only to charts that use MATLAB as the action language.
Code Generation
GeneratePreprocessorConditionals
— Whether generated code includes a preprocessor conditional
false
or 0 (default) | true
or 1
Whether the generated code includes a preprocessor conditional statement for the
variant conditions in the chart, specified as a numeric or logical 1
(true
) or 0 (false
). This property applies
only when generating code with Embedded Coder®. For more information, see Control Indicator Lamp Dimmer Using Variant Conditions.
C Action Language
EnableBitOps
— Whether to use bit operations
false
or 0 (default) | true
or 1
Whether to use bit operations in state and transition actions in the chart,
specified as a numeric or logical 1 (true
) or 0
(false
). This property applies only to charts that use C as the
action language.
Debugging
Debug
— Debugger properties
Stateflow.ChartDebug
object
Debugger properties for the chart, specified as a Stateflow.ChartDebug
object with this property:
Breakpoints.OnEntry
— Whether to set theOn Chart Entry
breakpoint, specified as a numeric or logical 1 (true
) or 0 (false
).
For more information, see Set Breakpoints to Debug Charts.
Example: chart.Debug.Breakpoints.OnEntry = true;
Graphical Appearance
Editor
— Editor
Stateflow.Editor
object
This property is read-only.
Editor for the chart, specified as a Stateflow.Editor
object. You can use this object to control the position,
size, and magnification level of the Stateflow Editor window.
Visible
— Whether editor is displaying chart
true
or 1 | false
or 0
Whether the Stateflow Editor window is displaying the chart, specified as a numeric or logical
1 (true
) or 0 (false
).
ChartColor
— Background color
[1 0.9608 0.8824]
(default) | [red green blue]
Background color for the chart, specified as a three-element numeric vector of the
form [red green blue]
that specifies the red, green, and blue
values. Each element must be in the range between 0 and 1.
StateColor
— Color for states
[0 0 0]
(default) | [red green blue]
Color for the boxes, functions, and states in the chart, specified as a
three-element numeric vector of the form [red green blue]
that
specifies the red, green, and blue values. Each element must be in the range between 0
and 1.
TransitionColor
— Color for transitions
[0.2902 0.3294 0.6039]
(default) | [red green blue]
Color for transitions in the chart, specified as a three-element numeric vector of
the form [red green blue]
that specifies the red, green, and blue
values. Each element must be in the range between 0 and 1.
JunctionColor
— Color for junctions
[0.6824 0.3294 0]
(default) | [red green blue]
Color for junctions in the chart, specified as a three-element numeric vector of
the form [red green blue]
that specifies the red, green, and blue
values. Each element must be in the range between 0 and 1.
StateFont
— Font for state labels
Stateflow.StateFont
object
Font for the box, function, and state labels in the chart, specified as a Stateflow.StateFont
object with these properties:
Name
— Font name, specified as a string scalar or character vector. This property also determines the font for annotations in the chart.Angle
— Font angle, specified as"NORMAL"
or"ITALIC"
.Weight
— Font weight, specified as"NORMAL"
or"BOLD"
.Size
— Default font size for new boxes, functions, and states, specified as a scalar. This property also determines the default font size for new annotations in the chart.
Example: chart.StateFont.Name = "Arial";
Example: chart.StateFont.Angle = "ITALIC";
Example: chart.StateFont.Weight = "BOLD;
Example: chart.StateFont.Size = 8;
StateLabelColor
— Color for state labels
[0 0 0]
(default) | [red green blue]
Color for the box, function, and state labels in the chart, specified as a
three-element numeric vector of the form [red green blue]
that
specifies the red, green, and blue values. Each element must be in the range between 0
and 1.
TransitionFont
— Font for transition labels
Stateflow.TransFont
object
Font for the transition labels in the chart, specified as a Stateflow.TransFont
object with these properties:
Name
— Font name, specified as a string scalar or character vector.Angle
— Font angle, specified as"NORMAL"
or"ITALIC"
.Weight
— Font weight, specified as"NORMAL"
or"BOLD"
.Size
— Default font size for new transitions, specified as a scalar.
Example: chart.TransitionFont.Name = "Arial";
Example: chart.TransitionFont.Angle = "ITALIC";
Example: chart.TransitionFont.Weight = "BOLD";
Example: chart.TransitionFont.Size = 8;
TransitionLabelColor
— Color for transition labels
[0.2902 0.3294 0.6039]
(default) | [red green blue]
Color for the transition labels in the chart, specified as a three-element numeric
vector of the form [red green blue]
that specifies the red, green,
and blue values. Each element must be in the range between 0 and 1.
Hierarchy
Machine
— Machine that contains chart
Stateflow.Machine
object
This property is read-only.
Machine that contains the chart, specified as a Stateflow.Machine
object.
Path
— Location of chart in model hierarchy
character vector
This property is read-only.
Location of the chart in the model hierarchy, specified as a character vector.
Dirty
— Whether chart has changed
true
or 1 | false
or 0
Whether the chart has changed after being opened or saved, specified as a numeric
or logical 1 (true
) or 0 (false
).
Locked
— Whether chart is locked
false
or 0 (default) | true
or 1
Whether the chart is locked, specified as a numeric or logical 1
(true
) or 0 (false
). Enable this property to
prevent changes in the chart.
Iced
— Whether chart is locked
false
or 0 (default) | true
or 1
This property is read-only.
Whether the chart is locked, specified as a numeric or logical 1
(true
) or 0 (false
). This property is
equivalent to the property Locked
, but is used internally to
prevent changes in the chart during simulation.
Identification
Description
— Description
""
(default) | string scalar | character vector
Description for the chart, specified as a string scalar or character vector.
Document
— Document link
""
(default) | string scalar | character vector
Document link for the chart, specified as a string scalar or character vector.
Tag
— User-defined tag
[]
(default) | any data type
User-defined tag for the chart, specified as data of any type.
Id
— Unique identifier
scalar
This property is read-only.
Unique identifier, specified as an integer scalar. Use this property to distinguish the chart from other objects in the model. 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 |
defaultTransitions | Identify default transitions in specified object |
dialog | Open properties dialog box |
view | Display object in editing environment |
fitToView | Zoom in on graphical object |
Examples
Create Empty Stateflow Chart
Call the function sfnew
to open a new Simulink model that contains an empty Stateflow chart.
sfnew
Access the Simulink.Root
object by calling the sfroot
function.
rt = sfroot;
Access the Stateflow.Chart
object by calling the find
function for the Simulink.Root
object.
chart = find(rt,"-isa","Stateflow.Chart");
Version History
Introduced before R2006aR2024a: Implicit ordering of transitions and parallel states will be removed
In a future release, the property
UserSpecifiedStateTransitionExecutionOrder
will be removed. This
property applies only to charts that use C as the action language.
When you enable this property, charts execute transitions and parallel states in the order you created them. You can also manually determine the execution order.
When you disable this property, charts execute transitions and parallel states according to an implicit order defined by physical position.
Transitions execute according to:
The hierarchical level of the parent of each transition.
The labels of the transition, in this order:
Labels with events and conditions.
Labels with events.
Labels with conditions.
No label.
The angular surface position of the transition source. The transition with the smallest clock position has the highest priority. For example, a transition with a 2 o'clock position has a higher priority than a transition with a 4 o'clock position. A transition with a 12 o'clock source position has the lowest priority.
Parallel states execute in this order:
Top to bottom.
Left to right.
To ensure your implicitly ordered charts remain compatible, set
UserSpecifiedStateTransitionExecutionOrder
to
true
.
R2023b: Convert to state transition table
To convert a chart to a state transition table, use the function convertToSTT
.
R2023a: Specify how to treat output data with dimension of length 1
With the new property TreatDimensionOfLengthOneAsFixedSize
, you can specify how charts treat
output data when at least one dimension has length 1. Prior to R2023a, charts treat output
data with a dimension of length 1 as fixed size, regardless of whether you specify the data
as having variable size.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)