Loop an animated plot

27 views (last 30 days)
Sai Sabarish M
Sai Sabarish M on 4 Sep 2019
Answered: Neuropragmatist on 4 Sep 2019
I have a plot that is animated. I have a presentation coming up and I want this plot to keep looping till I close the plot.
curve=animatedline('Linewidth',2);
set(gca,'XLim',[-0.7,0.7],'YLim',[-0.7,0.7],'ZLim',[-2,0]);
view(-24,42);
hold on;
for t = 0:0.07:10
x =R*cos(t);
y =R*sin(t);
z= vertvel*t;
pos=[x 0 0; 0 0 0; 0 0 z];
addpoints(curve,x,y,z);
scatter3(x,y,z,'d');
xlabel('X ');
ylabel('Y ');
zlabel('Z ');
title('Underwater Glider Simulation');
drawnow
pause(0.001);
end

Answers (1)

Neuropragmatist
Neuropragmatist on 4 Sep 2019
I would run your function once and generate a movie file, then insert the video into Powerpoint using the 'insert video' option and in Powerpoint you can set the video to loop indefinitely.
To make the video you can do something like this:
% video settings
frames = 500;
vfrate = 25; % frame rate of video
vname = 'videoname';
% figure settings
fhand = figure('visible','off');
set(gcf,'color','w');
set(gcf,'Renderer','zbuffer');
axis vis3d;
rotate3d on;
% video settings
writerObj = VideoWriter(vname,'MPEG-4');
writerObj.FrameRate = vfrate;
writerObj.Quality = 100;
open(writerObj);
% video frames
x = rand(100,1); % some random example data to plot
y = rand(100,1); % some random example data to plot
for i = 1:100
% do something to change your figure (i.e. plot new data)
cla; % clear the axis between frames to avoid plotting on top of the old data
plot(x(1:i),y(1:i),'k'); % this is just an example
axis([0 1 0 1]); % this just keeps the axis consistent between frames, you will have to personalise it to your data
% get ready for snapshot
drawnow;
cframe = getframe(gcf); % take shot
writeVideo(writerObj,cframe); % add it to video
end
close(writerObj); % close the video file so it's no longer 'in use' by Matlab
Sorry I couldn't adapt this for your code because a lot of the variables in your sample code are undefined.
Hope this helps,
M.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!