Save animation from PDE modeler

7 views (last 30 days)
Andrey Sekachev
Andrey Sekachev on 27 Apr 2021
Edited: Ayush on 27 May 2024
How to save animation from PDE modeler??

Answers (1)

Ayush
Ayush on 27 May 2024
Edited: Ayush on 27 May 2024
Hi,
As a work around to save animation from the PDE modeler, you can capture frames during the simulation and then write them into a video file. For this, you can use the "VideoWriter", "getframe" and "writeVideo" functions. Refer to the pseudo-code below:
% Assuming you have a PDE model 'model' and its solution 'result'
% Create a figure
fig = figure;
% Define the video writer
v = VideoWriter('pde_animation.avi');
open(v);
% Assume 'tlist' is the list of time points for the solution
for t = tlist
% Select the solution at time t
u = result.NodalSolution(:, t);
% Plot the solution
pdeplot(model, 'XYData', u);
% Capture the plot as a frame
frame = getframe(fig);
% Write the frame to the video
writeVideo(v, frame);
end
% Close the video file
close(v);
In the above example, it can be seen that to create a video, I'm using the "VideoWriter" function, which defines the format of the video to be saved. The result plots at every time instance are used as frames for my video, for which the "getframe" and "writeVideo" functions help me.
For more information on the "VideoWriter" and "getframe" functions, refer to the below documentations:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!