Main Content

Chart

Implement control logic with finite state machine

  • Chart block

Libraries:
Stateflow

Description

The Chart block graphically represents a finite state machine. In a Stateflow® chart, states and transitions form the basic building blocks of a sequential modal logic system. States correspond to operating modes and transitions represents the passage of the system from one operating mode to another. For more information, see Model Finite State Machines by Using Stateflow Charts.

To implement control logic, Stateflow charts can use MATLAB® or C as the action language. For more information, see Differences Between MATLAB and C as Action Language Syntax.

Examples

Ports

Input

expand all

When you create input data in the Stateflow chart using the Symbols pane, Stateflow creates a corresponding input port on the Chart block.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus | string

Output

expand all

When you create output data in the Stateflow chart by using the Symbols pane, Stateflow creates a corresponding output port on the Chart block.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus | string

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Note

Charts also have Subsystem (Simulink) block parameters that you can access by right-clicking the chart and clicking Block Parameters (Subsystem). However, updating these parameters is not recommended.

Method to update or wake up a Stateflow chart, specified as Inherited, Discrete, or Continuous.

Inherited

Input from the Simulink model determines when the chart wakes up during a simulation.

If you define input events for the chart, the signal from the Simulink block connected to the trigger port triggers the chart. The Simulink signal can be Rising, Falling, or Either (rising and falling), or in response to a Function Call. For more information, see Activate a Stateflow Chart by Sending Input Events.

If you do not define input events, the Stateflow chart implicitly inherits triggers from the Simulink model. These implicit events are the discrete or continuous sample times of the Simulink signals that provide inputs to the chart. If you define data inputs, the chart wakes at the rate of the fastest data input. If you do not define any data input for the chart, the chart wakes up as defined by the execution behavior of its parent subsystem.

Discrete

The Stateflow chart wakes when the Simulink model generates an implicit event at regular time intervals that you specify in the Sample Time chart property. Other blocks in the Simulink model can have different sample times.

Continuous

The Stateflow chart updates its state during major time steps only, and computes outputs and local continuous variables during major and minor time steps. The chart can register zero crossings, which allows Simulink models to sample Stateflow charts whenever state changes occur. The Stateflow chart computes derivatives for local continuous variables. For more information, see Continuous-Time Modeling in Stateflow.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: ChartUpdate
Values: "INHERITED" (default) | "CONTINUOUS" | "DISCRETE"

Specify the time interval at which the chart wakes up during simulation. The default value indicates that the chart inherits the sample time from Simulink. For more information on specifying sample time, see Specify Sample Time (Simulink).

Do not use the Sample Time parameter in the Subsystem block parameters. Instead, use the Property Inspector.

Dependencies

To enable this parameter, set Update method to Discrete.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: SampleTime
Values: "-1" (default) | string scalar | character vector
Data Types: string | char

Whether to enable zero-crossing detection on state transitions in the chart. For more information, see Continuous-Time Modeling in Stateflow.

Dependencies

To enable this parameter, set Update method to Continuous.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: EnableZeroCrossings
Values: true or 1 (default) | false or 0
Data Types: logical

Whether to use bit operations in state and transition actions in the chart, specified as a numeric or logical 1 (true) or 0 (false).

Dependencies

To enable this parameter, set Action language to C.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: EnableBitOps
Values: false or 0 (default) | true or 1
Data Types: logical

Whether to create an active state data output port for the chart. For more information, see Monitor State Activity Through Active State Data.

Dependencies

To enable this parameter, create a Stateflow state, state transition table, or atomic subchart.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: HasOutputData
Values: false or 0 (default) | true or 1
Data Types: logical

Monitoring mode for the active state output data. For more information, see Monitor State Activity Through Active State Data.

Dependencies

To enable this parameter, enable Create output for monitoring.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: OutputMonitoringMode
Values: "ChildActivity" (default) | "LeafStateActivity"

Name of the active state data object for the state transition table.

Dependencies

To enable this parameter, enable Create output for monitoring.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: OutputPortName
Values: "ChartMode" (default) | string scalar | character vector
Data Types: string | char

Name of the active state data object for the state transition table.

Dependencies

To enable this parameter, enable Create output for monitoring.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: EnumTypeName
Values: "ChartModeType" (default) | string scalar | character vector
Data Types: string | char

Whether to define the enumerated data type for the active state data output manually90. For more information, see Define State Activity Enumeration Type.

Dependencies

To enable this parameter, enable Create output for monitoring.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: DoNotAutogenerateEnum
Values: false or 0 (default) | true or 1
Data Types: logical

Advanced

Whether to initialize the state configuration of the chart at time zero instead of at the first input event. For more information, see Execution of a Chart at Initialization.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: ExecuteAtInitialization
Values: false or 0 (default) | true or 1
Data Types: logical

Whether the data in the chart saturates on integer overflow. When you clear this parameter, the data in the chart wraps on integer overflow. For more information, see Handle Integer and Enumeration Overflow for Chart Data.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: SaturateOnIntegerOverflow
Values: true or 1 (default) | false or 0
Data Types: logical

Whether to initialize the output data every time the chart wakes up.

When you select this parameter, the chart resets its output values every time that the chart wakes up, not only at time 0. The chart resets the output values whenever function call, edge trigger, or clock tick triggers the chart. If you set an initial value for an output data object, the output resets to that value. Otherwise, the output resets to zero. Select this parameter to:

  • Ensure that all outputs are defined in every chart execution.

  • Prevent latching of outputs, that is, prevent values of outputs computed in previous executions.

  • Provide all chart outputs with a meaningful initial value.

For more information, see Initial value.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: InitializeOutput
Values: true or 1 (default) | false or 0
Data Types: logical

Whether the chart supports variable-size data. For more information, see Declare Variable-Size Data in Stateflow Charts.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: SupportVariableSizing
Values: true or 1 (default) | false or 0
Data Types: logical

Whether to export chart-level functions to other blocks in the Simulink model. For more information, see Export Stateflow Functions for Reuse.

Dependencies

To enable this parameter, add a function to your chart.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: ExportChartFunctions
Values: false or 0 (default) | true or 1
Data Types: logical

Whether exported functions from the chart are globally visible in the Simulink model. When this property is enabled, blocks throughout the model can call functions exported from the chart without using qualified notation.

Dependencies

To enable this parameter, enable Export chart level functions.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: AllowGlobalAccessToExportedFunctions
Values: false or 0 (default) | true or 1
Data Types: logical

Whether to enable super step semantics for the chart. Select this parameter to enable the chart to take multiple transitions in each time step until it reaches a stable state. This option is not available when you. For more information, see Super Step Semantics.

Dependencies

To enable this parameter, set Update method to Discrete.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: EnableNonTerminalStates
Values: false or 0 (default) | true or 1
Data Types: logical

The maximum number of transitions that can be completed in one super step. For more information, see Super Step Semantics.

Dependencies

To enable this parameter, enable Enable super step semantics.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: NonTerminalMaxCounts
Values: 1000 (default) | positive integer
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Action for Stateflow to take if super step exceeds maximum number of transitions in one super step. For more information, see Super Step Semantics.

Dependencies

To enable this parameter, enable Enable super step semantics.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: NonTerminalUnstableBehavior
Values: "Proceed" (default) | "Throw Error"

Since R2022b

Whether the chart treats output data with a dimension of length 1 as fixed size. When you select this parameter, the chart treats output data that have at least one dimension of length 1 as fixed size, regardless of whether you enable the Variable size data property. When you clear this parameter, the chart treats data with the Variable size property enabled as variable size.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: TreatDimensionOfLengthOneAsFixedSize
Values: true or 1 (default) | false or 0
Data Types: logical

Specify which block variants Stateflow analyzes during simulation and code generation. Based on the option you choose, Stateflow determines if the generated code must contain only the active choice or both active and inactive choices.

  • update diagram analyze all choices — When you select this option, Stateflow analyzes both active and inactive choices for incompatibilities in signal attributes and generates code only for the active choice.

  • code compile — When you select this option, 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.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: VariantActivationTime
Values: "update diagram analyze all choices" (default) | "code compile"

Action language to use to program the chart, specified as MATLAB or C. For more information, see Differences Between MATLAB and C as Action Language Syntax.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: ActionLanguage
Values: "MATLAB" (default) | "C"

State machine semantics implemented by the chart, specified as Classic, Mealy, or Moore. For more information, see Overview of Mealy and Moore Machines.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: StateMachineType
Values: "Classic" (default) | "Mealy" | "Moore"

Fixed-point properties

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 as fi objects.

  • Fixed-point & Integer — The chart treats all fixed-point and integer inputs as fi objects.

Dependencies

To enable this parameter, set Action language to MATLAB.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: TreatAsFi
Values: "Fixed-point" (default) | "Fixed-point & Integer"

Default fimath properties for the chart, specified as one of these values:

  • Same as MATLAB — The chart uses the same fimath object properties as the current default fimath object. The text box is dimmed and displays the current global fimath object in read-only form.

  • Specify other — Specify your own fimath object in the text box one of two ways:

    • Constructing the fimath object inside the text box.

    • Constructing the fimath object in the MATLAB or model workspace and then entering its variable name in the text box. If you use this option and plan to share your model with others, define the variable in the model workspace.

For more information, see fimath Object Construction (Fixed-Point Designer).

Dependencies

To enable this parameter, set Action language to MATLAB.

Programmatic Use

To set the chart parameter value programmatically, access the Stateflow.Chart object of the chart and change the object property by using dot notation.

Parameter: EmlDefaultFimath
Values: "Same as MATLAB Default" (default) | "Other:UserSpecified"

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a

expand all