Both of these requests can be accomplished as described below. The attached sample model, "stopStateflowExample.slx", provides an example for implementing these features.
1) Stop simulation within Stateflow diagram
This can be accomplished by creating a Simulink function in the Stateflow diagram that contains the "Stop Simulation" block connected to a constant block (with a positive value). When the logic of in the Stateflow diagram wants to stop the model, it simply calls this Simulink function. The attached model shows a simple implementation of this functionality.
The following documentation page gives further information on rules for using Simulink functions in Stateflow diagrams:
Run this command in MATLAB 2017a for documentation:
>> web(fullfile(docroot, 'stateflow/ug/simulink-functions-in-stateflow.html')
Or,
for latest release documentation please refer to:
2) Push button to stop simulation
Simulink includes a Push Button block in the Simulink > Dashboard library. This button can be connected to a constant block, such that when the button is pushed and held, the constant block changes its value. The input of the constant block is then used as an input to the Stateflow diagram to as a stop signal. This simple behavior is shown in the example model. Please refer to the following documentation page for more information on the Push Button block:
Run this command in MATLAB 2017a for documentation:
>> web(fullfile(docroot, 'simulink/slref/pushbutton.html'))
Or,
for latest release documentation please refer to:
Note that other blocks in the Dashboard library may be considered for this application, such as the Toggle Switch.
