Main Content

Divide a Long Simulation into Segments

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.

Goal of the Tutorial

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.

Step 1: Define the Operating Point

1. Open the sf_boiler model.

2. Open the Configuration Parameters dialog box.

3. Enable saving of an operating point. In the Data Import/Export pane:

   a. Select Final states.

   b. Enter a name, such as sf_boiler_ctx01.

   c. Select Save final operating point.

To complete this step programmatically, enter:

set_param("sf_boiler", ...
    SaveFinalState="on", ...
    FinalStateName="sf_boiler_ctx01", ...
    SaveOperatingPoint="on");

For more information, see Set Configuration Parameters Programmatically.

4. Define the start and stop times for this simulation segment. In the Solver pane, set Start time to 0 and Stop time to 400.

To complete this step programmatically, enter:

set_param("sf_boiler", ...
    StartTime="0", ...
    StopTime="400");

5. Click OK.

6. Start the 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.

7. Disable saving of an operating point. In the Configuration Parameters dialog box, in the Data Import/Export pane, clear the Save final operating point and Final states parameters and click OK.

This step prevents you from overwriting the operating point you saved in the previous step.

To complete this step programmatically, enter:

set_param("sf_boiler", ...
    SaveOperatingPoint="off", ...
    SaveFinalState="off");

Step 2: Load the Operating Point

1. Enable loading of an operating point. In the Configuration Parameters dialog box, in the Data Import/Export pane, select Initial state and enter the variable that contains the operating point of your chart: sf_boiler_ctx01.

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. In the Configuration Parameters dialog box, in the Solver pane, set Stop time to 600.

You do not need to enter a new start time because the simulation continues from where it left off.

To complete this step programmatically, enter:

set_param("sf_boiler",StopTime="600");

Step 3: Simulate the Specific Segment

When you simulate the model, the following output appears in the Scope (Simulink) block.

See Also

(Simulink) | (Simulink)

Related Topics