This example shows how to use operating points with Stateflow charts. An operating point is a snapshot of the state of a Simulink® model at a specific time during simulation. For a Stateflow® chart, an operating point includes:
Activity of chart states
Values of chart local data
Values of chart output data
Values of persistent data in MATLAB® functions and Truth Table blocks
For more information, see Using Operating Points in Stateflow.
Suppose that you want to simulate this model without starting from time t = 0.
This model simulates for 1400 seconds, but the output that interests you occurs sometime between t = 400 and 600. You can simulate the model, save the operating point at time t = 400, and then load that operating point for simulation between t = 400 and 600.
1. Open the sf_boiler model.
2. Enable saving of an operating point.
a. Open the Model Configuration Parameters dialog box and go to the Data Import/Export pane.
b. Select the Final states check box.
c. Enter a name, such as sf_boiler_ctx01
.
d. Select the Save final operating point check box.
e. Click Apply.
To complete this step programmatically, enter:
set_param('sf_boiler', ... 'SaveFinalState','on', ... 'FinalStateName','sf_boiler_ctx01', ... 'SaveOperatingPoint','on');
For details about setting model parameters, see
.set_param
3. Define the start and stop times for this simulation segment.
a. In the Model Configuration Parameters dialog box, go to the Solver pane.
b. For Start time, enter 0
.
c. For Stop time, enter 400
.
c. Click OK.
To complete this step programmatically, enter:
set_param('sf_boiler', ... 'StartTime','0', ... 'StopTime','400');
4. Start simulation. When you simulate the model, you save the complete operating point at t = 400 in the variable sf_boiler_ctx01
in the MATLAB base workspace.
5. Disable saving of an operating point. This step prevents you from overwriting the operating point you saved in the previous step.
a. Open the Model Configuration Parameters dialog box and go to the Data Import/Export pane.
b. Clear the Save final operating point check box.
c. Clear the Final states check box.
d. Click OK.
To complete this step programmatically, enter:
set_param('sf_boiler', ... 'SaveOperatingPoint','off', ... 'SaveFinalState','off');
1. Enable loading of an operating point.
a. Open the Model Configuration Parameters dialog box and go to the Data Import/Export pane.
b. Select the Initial state check box.
c. Enter the variable that contains the operating point of your chart, sf_boiler_ctx01
.
d. Click Apply.
To complete this step programmatically, enter:
set_param('sf_boiler', ... 'LoadInitialState','on', ... 'InitialState','sf_boiler_ctx01');
2. Define the new stop time for this simulation segment. You do not need to enter a new start time because the simulation continues from where it left off.
a. In the Model Configuration Parameters dialog box, go to the Solver pane.
b. For Stop time, enter 600
.
c. Click OK.
To complete this step programmatically, enter:
set_param('sf_boiler','StopTime','600');
When you simulate the model, the following output appears in the Scope block.