sanjana asked . 2021-10-11

How do I freeze a Simulation in Simulink, close MATLAB

I would like to run a simulation in Simulink following the below steps:
 
1. Run the simulation from time 0 to 10s
 
2. Stop the simulation at time 10s and save all the states and operating points of the simulation at that timestep
 
3. Close MATLAB
 
4. Re-open MATLAB/Simulink and then re-run that same model starting from time 10s to 20s and starting from the operating point and states I saved at time 10s. I do not want the model to restart the simulation from time 0 and lose the final simulation state of step 1.
 
How can the above workflow be achieved? 

operating , point , simulink , matlab

Expert Answer

John Williams answered . 2024-12-21 17:18:45

This is an ideal application for a "ModelOperatingPoint" object. The "ModelOperatingPoint" object is a MATLAB object that stores information about the final state of the simulation at a given stop time. For this use case, that stop time is 10 seconds. You can then use the "ModelOperatingPoint" object to run the same model again but this time starting from the time-step and simulation state that was saved at 10 seconds till any new stop time you specify without losing the data that was generated during the initial run.
To get started on "ModelOperatingPoint", please refer to the following documentation link:
https://www.mathworks.com/help/releases/R2020b/simulink/ug/saving-and-restoring-simulation-operating-point.html
Below are two scripts, executed in sequence, that should execute the above required workflow for the attached example Simulink model called "vdpOperatingPointExample.slx". The attached model "vdpOperatingPointExample.slx" is a copy of one of the Simulink shipped examples called "vdp" that models the van der Pol equation. More resources on how to programmatically control and simulate the "vdp" shipped example can be found here:
https://www.mathworks.com/help/releases/R2020b/simulink/ug/using-the-sim-command.html
To demonstrate the use of model operating points for saving a model's operating point and re-starting the simulation from that point, first, download the attached model: "vdpOperatingPointExample.slx".
Then, in the same MATLAB working directory as the downloaded Simulink model, please execute the below script:
open_system('vdpOperatingPointExample') %open the Simulink model

%make sure the initial state of the model is set to default empty
set_param('vdpOperatingPointExample','InitialState','[]')

%enable the option of saving the last simulation operating point
set_param('vdpOperatingPointExample','SaveFinalState','on','FinalStateName',...
'myOperPoint','SaveOperatingPoint','on');

%run the simulation for 10 seconds
% because the last state at time equal to 10 seconds will be saved
simOut = sim('vdpOperatingPointExample','StopTime','10')

% when a Simulink model completes its simulation
% it will save the output in a structure by default called "simOut".
% Below, the operating point called "myOperPoint" is being extracted
% and saved locally in the MATLAB base workspace 
myOperPoint = simOut.myOperPoint

% Save the operating point that was extracted (the one at time 10)
% inside a MAT-file called "data.mat" to be able to close MATLAB
% and not lose the data
save('data','myOperPoint')

save_system('vdpOperatingPointExample') %save changes to model

Now you can close MATLAB and then execute the below script to extract the saved operating point and then start the simulation from time 10s:

open_system('vdpOperatingPointExample')

%{
The below command is optional. It was added it just to point
out that you probably would want to turn off the option
of saving the final operating point because we don't need
it anymore and we don't want it to interfere with
the original operating point
%}

% disable the option of saving the last operating point
set_param('vdpOperatingPointExample','SaveFinalState','off',...
'SaveOperatingPoint','off'); 

%%%%%%%%%%%%%%%

% The below is mandatory

% load the operating point we saved in the data.mat MAT-file
load data

% set the initial state of the system to be the operating point
% last saved in the last simulation
set_param('vdpOperatingPointExample','LoadInitialState','on','InitialState',...
'myOperPoint');

% execute the simulation for stop time 20 seconds now
% it should start from t = 10s
sim('vdpOperatingPointExample','StopTime','20')

%reset initial state to default empty when sim is over
set_param('vdpOperatingPointExample','InitialState','[]')

 

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.