Skip to Main Content Skip to Search
Product Documentation

Best Practices for Using the SimState of a Chart

Use MAT-Files to Save a SimState for Future Use

To save a SimState from the MATLAB base workspace, save the variable with final state data in a MAT-file.

For example, type at the command prompt:

save('sf_car_ctx01.mat', 'sf_car_ctx01')

For more information, see save in the MATLAB documentation.

Use Scripts to Save SimState Commands for Future Use

To save a list of SimState commands for future use, copy them from a procedure and paste them in a MATLAB script.

For example, to reuse the commands in Dividing a Long Simulation into Segments, you can store them in a script named sf_boiler_simstate_commands.m:

% Load the model.
sf_boiler;

% Set parameters to save the SimState at the desired time.
set_param('sf_boiler','SaveFinalState','on','FinalStateName',...
['sf_boiler_ctx01'],'SaveCompleteFinalSimState','on');

% Specify the start and stop times for the simulation segment.
set_param('sf_boiler','StartTime','0','StopTime','400');

% Simulate the model.
sim('sf_boiler');

% Disable saving of the SimState to avoid overwriting.
set_param('sf_boiler','SaveCompleteFinalSimState','off', ...
'SaveFinalState','off');

% Load the SimState.
set_param('sf_boiler', 'LoadInitialState', 'on', ...
'InitialState', ['sf_boiler_ctx01']);

% Specify the new stop time for the simulation segment.
set_param('sf_boiler','StopTime','600');

% Simulate the model.
sim('sf_boiler');
  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS