Test a Unique Chart Configuration
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 test the response of the
old_sf_car model to
a sudden change in value for
This model simulates for 30 seconds, but you want to see what happens when the value of
gear changes at t = 10. You can simulate the model, save the operating
point at t = 10, load and modify the operating point, and then simulate again between t = 10
Define the Operating Point
Open the model
Open the Configuration Parameters dialog box.
Enable saving of an operating point. In the Data Import/Export pane:
Select Final states.
Enter a name, such as
Select Save final operating point.
Define the start and stop times for this simulation segment. In the Solver pane, set Start time to
0and Stop time to
Start the simulation.
When you simulate the model, you save the complete operating point at t = 10 in the variable
old_sf_car_ctx01in the MATLAB base workspace.
At t = 10, the engine is operating at a steady-state value of 2500 RPM.
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.
Load the Operating Point and Modify Values
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:
Define an object handle for the operating point values of the
shift_logicchart. At the MATLAB command prompt, enter:
blockpath = "old_sf_car/shift_logic"; c = old_sf_car_ctx01.get(blockpath);
If the chart appears highlighted in the model window, you can specify the block path using
c = old_sf_car_ctx01.get(gcb);
Look at the contents of the operating point.
c = Block: "shift_logic" (handle) (active) Path: old_sf_car/shift_logic Contains: + gear_state "State (AND)" (active) + selection_state "State (AND)" (active) gear "Block output data" double [1, 1]
The operating point of your chart contains a list of states and data in hierarchical order.
Highlight the states that are active in your chart at t = 10.
At the command prompt, type:
In the chart, all active states appear highlighted.
To check if a single state is active, you can use the
isActivemethod. For example, type:
This command returns true (1) when a state is active and false (0) otherwise. For information on other methods, see Methods for Interacting with the Operating Point of a Chart.
Change the active substate of
Use this command:
The newly active substate appears highlighted in the chart.
Change the value of output data
When you type
c.gearat the command prompt, you see a list of data properties similar to this:
ans = Description: 'Block output data' DataType: 'double' Size: '[1, 1]' Range: [1x1 struct] InitialValue: [1x0 double] Value: 4
You can change the value of
gearfrom 4 to 1 by typingHowever, you cannot change the data type or size of
c.gear.Value = 1;
gear. Also, you cannot specify a new value that falls outside the range set by the Minimum and Maximum parameters. For details, see Rules for Modifying Data Values .
Save the modified operating point.
old_sf_car_ctx01 = old_sf_car_ctx01.set(blockpath,c);
Test the Modified Operating Point
Define the new stop time for the simulation segment to test. In the Configuration Parameters dialog box, in the Solver pane, set Stop time to
You do not need to enter a new start time because the simulation continues from where it left off.
Start the simulation.