Although I used 'drawnow' and 'hold on', last plot still appears in animation - MATLAB -
i read lot of answers here, reason animation still doesn't work expected.
the axis range should vary frame frame. 'hurricane center' caption should remain in center time, captions previous frames must erased. also, i'm afraid of data previous parts remain.
i used hold on
, draw now
still happens.
the animation can seen here:
code:
v = videowriter('test_video.avi'); v.framerate = 4; v.open() hold on i=1:length(relevant(1,1,:)) if isempty(relevant) == 0 title('lightning around hurricane jerry') grid on ylim([interp_jerry(i,2)-radius interp_jerry(i,2)+radius]) xlim([interp_jerry(i,3)-radius interp_jerry(i,3)+radius]) ylabel('latitude') xlabel('longitude') text(interp_jerry(i,3),interp_jerry(i,2),txt1); scatter(relevant(:,3,i),relevant(:,2,i),'.'); drawnow pause(0.1); v.writevideo(getframe(fig)); end end v.close()
the best of 2 worlds:
v = videowriter('test_video.avi'); v.framerate = 4; v.open() hold on; i=1:length(relevant(1,1,:)) if ~isempty(relevant) % corrected if == 1 % prepare first plot , save handles of graphical objects ht = text(interp_jerry(i,3),interp_jerry(i,2),txt1); hold on; hs = scatter(relevant(:,3,i),relevant(:,2,i),'.'); ylabel('latitude') xlabel('longitude') title('lightning around hurricane jerry') grid on else % update graphical objects set(ht, 'position', [interp_jerry(i,3), interp_jerry(i,2)]); set(hs, 'xdata', relevant(:,3,i) , 'ydata' , relevant(:,2,i)); end ylim([interp_jerry(i,2)-radius interp_jerry(i,2)+radius]) xlim([interp_jerry(i,3)-radius interp_jerry(i,3)+radius]) drawnow pause(0.1); v.writevideo(getframe(fig)); end end v.close()
wiki
Comments
Post a Comment