How to Freeze, Save, and Resume Simulink Simulations
Simulink allows you to capture the entire internal state of a simulation (integrator states, solver history, discrete delays, block execution memory) as a SimState object. You can save this state to disk and resume execution from that exact time point.
Method 1: Programmatic Workflow with MATLAB Code
Step 1: Run and Save the SimState (Phase 1: 0 to 10 Seconds)
Configure model parameters to export the complete operating state at the end of the run.
model = 'vdp'; % Replace with your model name
load_system(model);
% Configure model to save complete SimState
set_param(model, 'SaveCompleteSimState', 'on');
set_param(model, 'SaveFinalState', 'on');
set_param(model, 'FinalStateName', 'savedSimState');
set_param(model, 'StopTime', '10.0');
% Run Phase 1
out1 = sim(model);
% Extract and save the SimState to a .mat file
frozenState = out1.savedSimState;
save('checkpoint_t10.mat', 'frozenState');
fprintf('Simulation frozen and saved at t = 10s.\n');
Step 2: Load the Saved State and Resume (Phase 2: 10 to 25 Seconds)
Load the stored SimState object, set it as the initial state, and extend the stop time.
% Load the saved state from disk
load('checkpoint_t10.mat', 'frozenState');
% Configure model to start from the saved operating point
set_param(model, 'LoadInitialState', 'on');
set_param(model, 'InitialState', 'frozenState');
% Set new time boundaries
set_param(model, 'StartTime', '10.0');
set_param(model, 'StopTime', '25.0');
% Resume simulation
out2 = sim(model);
fprintf('Simulation resumed from t = 10s to t = 25s successfully.\n');
Method 2: GUI Configuration in Simulink
- Open your model and press Ctrl+E to open Configuration Parameters.
- Select Data Import/Export in the left tree.
- To Save State:
- Check Final states.
- Set variable name (e.g.
xFinal). - Check Save complete SimState in an operating point object.
- To Resume State:
- Check Initial state.
- Enter the workspace variable name (e.g.
xFinal). - Update Start time in the Solver pane to match the freeze time.
Method 3: Live Interactive Pause and Resume
Control live execution directly from the MATLAB command window or scripts:
% Pause a running simulation
set_param(model, 'SimulationCommand', 'pause');
% Resume a paused simulation
set_param(model, 'SimulationCommand', 'continue');
% Stop and terminate
set_param(model, 'SimulationCommand', 'stop');
SimState Rules and Limitations
| Component | Supported in SimState | Notes |
|---|---|---|
| Continuous Integrators | Yes | Preserves derivatives and solver history. |
| Discrete Unit Delays / Memory | Yes | Retains exact buffer values. |
| Stateflow Charts | Yes | Stores active state hierarchy and local variables. |
| MATLAB Function Blocks | Yes | Persistent variables are stored. |
| Structural Model Edits | No | Do not alter model topology between save and resume. |
Fast Restart Tip: If you plan to run multiple sweeps starting from the same frozen baseline, enable Fast Restart (
set_param(model, 'FastRestart', 'on')). This skips model recompilation on every resume.Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Explore similar technical troubleshooting questions and verified MATLAB solutions: