make gif of visual simulation
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Is there a way to record a series of plotted frames and save it as a gif?
I have a simulation of a quadrotor that I can plot in real time: I simply plot two crossed lines in the position and orientation of the quadrotor and then delete this and update it as the simulation updates. As a result the visual simulation demonstrates the dynamics in real time and appears realistic.
However if I try to add any sort of frame capture the simulation becomes painfully tedious to watch. Is there a way to simply record each frame and play it back as a gif at whatever speed I want? I tried to do this using movie(fig,F,150) where F is an array containing the frames, but this plays very slowly - nowhere near 150 hz which is the simulation update rate.
-Thanks
Thomas
0 comentarios
Respuestas (1)
Walter Roberson
el 27 de Feb. de 2017
Yes, there is an explanation in https://www.mathworks.com/help/matlab/ref/imwrite.html#btv452g-1 imwrite() "Write Animated Gif"
"I simply plot two crossed lines in the position and orientation of the quadrotor and then delete this and update it as the simulation updates"
Instead of doing that, draw the plot once and record the handle of what you need to update. Then in each iteration of the loop, update the XData and YData properties (and whatever label.) This is a lot faster than deleting the object and replotting.
2 comentarios
Walter Roberson
el 27 de Feb. de 2017
ax = gca();
max_frame = 1000;
frames(max_frame) = struct('cdata', [], 'colormap', []);
for counter = 1 : maxframe
if counter == 1
h = plot3(ax, ....)
title(ax, ...)
xlabel(ax, ....)
set(ax, 'xlimmode', 'manual', 'ylimmode', 'manual');
else
set(h, 'XData', new_x, 'YData', new_y, 'ZData', new_z);
end
drawnow()
frames(counter) = getframe(ax);
end
Then afterwards you can write the data in frames into an animated gif.
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!