Making video from an animation

조회 수: 1 (최근 30일)
Hari krishnan
Hari krishnan 2019년 5월 7일
댓글: Hari krishnan 2019년 5월 15일
I am plotting few graphs and trying to make movie out of it. The code runs without error. But unfortunately the video is not saved. Can anyone help me on this?
a = smoothed_final_plot_mat(:,3:end);
np = (size(a,2)-1)/2; % number of particles
t = a(2:end,1);
arena_image = imread('arena_pic.png');
h1 = axes ;
image('XData',[0 6890],'YData',[0 5000],'CData',arena_image) ; % set your limits
set(h1,'YDir','normal');
hold on
ax = gca;
ax.YDir = 'reverse';
axis([0 6890 0 5000])
h = zeros(1,np); % ants handles
hold on
writerObj = VideoWriter('output3.avi'); % Name it.
writerObj.FrameRate = 60; % How many frames per second.
open(writerObj);
for ii = 2:25:size(a,1) % frames
k = 0;
t = a(ii,1); % time of current frame
str = sprintf('Time in seconds = %f', t);
title(str)
label = cellstr(num2str(unique(a(1,2:end))'));
hold on
for jj = 2:2:np*2 % ant handles
x = a(ii,jj);
y = a(ii,jj+1);
k = k + 1;
h(k) = plot(x,y,'--or');
hi(k) = text(x, y, label(k), 'VerticalAlignment','bottom', 'HorizontalAlignment','right'); %#ok<SAGROW>
h2(k) = plot(a(max(1,ii-150):ii,jj), a(max(1,ii-150):ii,jj+1)); %#ok<SAGROW>
end
drawnow
pause(0.00001)
delete(h)
delete(hi)
delete(h2)
hold off
end
frame = getframe(gcf); % 'gcf' can handle if you zoom in to take a movie.
writeVideo(writerObj, frame);
close(writerObj);

채택된 답변

KSSV
KSSV 2019년 5월 8일
YOur writevideo command is out side the loop..this should be inside the loop.
  댓글 수: 1
Hari krishnan
Hari krishnan 2019년 5월 15일
Thank you very much, it worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by