Save and Restore Operating Points for Stateflow Charts
An operating point is a snapshot of a Simulink® model during simulation. If your model contains a Stateflow® chart, the operating point includes information about:
Active states
Chart output data
Chart, state, and function local data
Persistent variables in MATLAB® functions and truth tables
You can save the state of a model at a certain time step as an operating point and then use that operating point as the initial state for a simulation. For example, suppose that your simulation starts with an initialization phase. If you save an operating point after the model completes the initialization phase, you can use the operating point as the initial state for your model and get the results of a continuous simulation without starting from time t = 0. For more information, see Use Operating Points to Specify Initial State of Simulation.
You can also use operating points to test the response of a Stateflow chart to different settings, including configurations that are difficult to reach in simulation. You can modify an operating point by changing the values of local, output, or persistent data, the states that are currently active, and the previous state activity recorded by history junctions midway through a simulation. Then, you can use the modified operating point as a starting point of a simulation to test how the chart responds to your changes. For more information, see Test Difficult-to-Reproduce Chart Configurations.
Save Operating Points
To save the final operating point of a Simulink model, select the configuration parameters Final states (Simulink) and Save final operating
point (Simulink), specify a variable for the operating point for the model, and run a
simulation. Then, access the operating point information for your Stateflow chart by calling the get
(Simulink) function
using the operating point for the model and the block path to the chart.
For example, suppose that xFinal
is the operating point for the model
sf_car
, which contains the chart shift_logic
.
To access the operating point information for this chart, enter:
op = get(xFinal,"sf_car/shift_logic")
op = Block: "shift_logic" (handle) (active) Path: sf_car/shift_logic Contains: + gear_state "State (AND)" (active) + selection_state "State (AND)" (active) gear "State output data" gearType [1, 1] down_th "Local scope data" double [1, 1] up_th "Local scope data" double [1, 1]
The operating point lists the states, boxes, functions, and data in the chart in hierarchical order. If name conflicts exist, one or more underscores appear at the end of a name so that all objects have unique identifiers.
To access the operating point information for an object in the chart, use dot notation.
For example, to access the operating point information for the top-level state
gear_state
, enter:
op.gear_state
ans = State: "gear_state" (handle) (active) Path: sf_car/shift_logic/gear_state Contains: + first "State (OR)" + fourth "State (OR)" + second "State (OR)" + third "State (OR)" (active)
Similarly, to access the operating point information for the chart output
gear
, enter:
op.gear
ans = Description: 'State output data' DataType: 'gearType' Size: '[1, 1]' Range: [1×1 struct] InitialValue: [] Value: third
For more information about this example, see Simulate Chart as a Simulink Block with Local Events.
Note
Stateless flow charts have an empty operating point because they do not contain states or persistent data.
Copy Operating Points
To create a copy of the operating point for a Stateflow chart, call the clone
function. For example, suppose that
you try to copy the operating point op
by entering:
op1 = op; op2 = clone(op);
In this case, op1
refers to the same operating point as
op
, so modifying op1
also modifies
op
. In contrast, op2
refers to a different
operating point that you can modify without modifying op
.
Note
The clone
function copies the operating point information for
the entire Stateflow chart. You cannot copy the operating point information for a state or data
object.
Modify Operating Point Values
To test the response of your Stateflow chart to different settings, you can modify an operating point by changing the values of the local, output, or persistent data, the states that are currently active, and the previous state activity recorded by history junctions during a simulation.
Modify Data Values
To modify the values of local, output, or persistent data, change the
Value
property of the operating point. For example, suppose that
op
contains the operating point for a chart. To modify value of a
chart output called output
, enter:
op.output.Value = newValue;
When you modify data values:
You cannot change the data type or size.
Refer to elements of a vector or matrix by using one-based indexing delimited by parentheses and commas, even if your chart uses C as the action language.
New values for numeric data must be within the range that you specify in the Minimum and Maximum parameters. For more information, see Limit range.
For enumerated data types, you can choose only enumerated values from the type definition.
You cannot modify the values of persistent data in custom C code or external MATLAB code.
Modify Current State Activity
To change the states that are currently active in an operating point, call the
setActive
function using a leaf state as
an argument. This function maintains state consistency by:
Exiting and entering the appropriate states
Resetting temporal counters for newly active states
Updating values of active state data
Enabling or disabling function-call subsystems and Simulink functions that bind to states
However, the chart does not perform exit
actions for the
previously active states or entry
actions for the newly active state.
Additionally, the state does not reinitialize any state-parented local data. If you want
these actions to occur, you must execute them separately. For example, if your state
actions assign values to data, you must assign the values explicitly as described in Modify Data Values.
Modify Previous State Activity
To change the previously active state recorded by a history junction, call the
setPrevActiveChild
function
using the state that contains the history junction as an argument. The state must not be
active when you call this function.
Load Modified Operating Point Information
To load modified operating point information for a Stateflow chart into the operating point for a Simulink model, call the set
(Simulink)
function. For example, if xFinal
is the operating point for the model
sf_car
and op
contains the modified operating
point information for the chart shift_logic
, you can save the modified
operating point xModified
by entering:
xModified = set(xFinal,"sf_car/shift_logic",op);
Note
The set
function loads the operating point information for the
entire Stateflow chart. You cannot load the operating point information for a state or data
object.
Restore Operating Points
To use an operating point as the initial state for a simulation, set the configuration parameter Initial state (Simulink) and specify the variable name for the operating point for the model. When you simulate your model, the simulation starts at the time of the operating point. For more information, see Use Model Operating Point for Faster Simulation Workflow (Simulink).
Limitations on Operating Points
Continuous-Time Charts
Operating points for continuous-time charts are read-only. You can save an operating point for a continuous-time chart and use it as the initial state for a simulation. However, you cannot modify the state activity or any data values in the operating point. For more information on continuous-time charts, see Continuous-Time Modeling in Stateflow.
Charts That Use Edge Detection
Stateflow charts that use edge detection operators do not support operating points. If your model contains a chart that uses edge detection, attempting to save the final operating point results in a compile-time error. For more information on edge detection operators, see Detect Changes in Data and Expression Values.
See Also
Model Settings
- Initial state (Simulink) | Final states (Simulink) | Save final operating point (Simulink)
Objects
Stateflow.op.BlockOperatingPoint
|Stateflow.op.OperatingPointContainer
|Stateflow.op.OperatingPointData
Functions
setActive
|setPrevActiveChild
|clone
|get
(Simulink) |set
(Simulink)