How to solve two axes in failure VideoWriter?

2 次查看(过去 30 天)
for example, my code framework as follows:
  1. t=0:.1:2*pi;
  2. plot(t,sin(t),'k');
  3. axes('position',[0.55,0.55,0.3,0.3]);
  4. plot(t,sin(t), 'b');
there is two axes in one figure.
so when i use VideoWriter to export file.avi,the video is broken.
i think the proble maybe because of the axes(when i comment "axes('position',[0.55,0.55,0.3,0.3]);",all success!)
my question is how to export mp4/avi videos when the frame has two axes like the kind of above code?
  2 个评论
Ganesh Regoti
Ganesh Regoti 2020-1-31
Hi Can you share the exact code? I don't think the issue is with axes. I have tried with another example and it worked.
Refer to the following link,
Here is the code with tweak
for i = 1:10
figure(1)
% imshow(processo(:,:,1,i))
hold on
plot(0+i,0+i,'o')
plot(1+i,i+i,'o')
plot(2+i,2+i,'o')
axes('position',[0.55,0.55,0.3,0.3]);
plot(3+i,3+i,'o')
plot(4+i,4+i,'o')
hold off
F(i) = getframe(gcf) ;
drawnow
end
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
writerObj.FrameRate = 10;
% set the seconds per image
% open the video writer
open(writerObj);
% write the frames to the video
for i=1:length(F)
% convert the image to a frame
frame = F(i) ;
writeVideo(writerObj, frame);
end
% close the writer object
close(writerObj);
Wang Benliang
Wang Benliang 2020-2-27
it works! thank you! Problem happens when i use two axes handle in one loop to export video, I solve it by export figures first, and combined it into video. Thank you again, your code also give me some idea!

请先登录,再进行评论。

回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by