【问题标题】:MATLAB video only updating for one loopMATLAB 视频仅更新一个循环
【发布时间】:2016-08-18 02:11:56
【问题描述】:

我的代码为filters 过滤器数量绘制了一个脉冲roundtrips 次数。我正在尝试为每次往返创建此脉冲的视频,以便视频中有roundtrips*filters 帧数。到目前为止,这就是我的代码的样子:

writerObj = VideoWriter('pulses.avi'); % Name it.
writerObj.FrameRate = 60; % How many frames per second.
fid=figure;
hold on

for kk=1:filters
    open(writerObj);

    for ii=1:roundtrips
              %fid=figure;

          pause(0.1);
          figure(fid)
          subplot(2,1,1);plot(TT,abs(U1).^2);xlabel('Time (ps)','fontsize',12);ylabel('Power (W)','fontsize',12);
          title(['roundtrips = ',num2str(ii),'m']);
          subplot(2,1,2);plot(FF,abs(fftshift(ifft((U1)))).^2);xlabel('Freq. (THz)','fontsize',12);ylabel('Spectrum (arb. units)','fontsize',12)


          frame = getframe(gcf); % 'gcf' can handle if you zoom in to take a movie.
          writeVideo(writerObj, frame);
     end
    hold off
    close(writerObj);
end

问题是它只显示视频中的roundtrips 脉冲数。我尝试将open(writerObj) 移动到kk 循环之前,但我收到一条错误消息。有什么想法吗?

【问题讨论】:

  • 你收到了什么错误信息?
  • 我猜你的问题是 openclose 位于循环内。您是否将 openclose 都移到了循环之外?
  • 另外,您不需要每次都使用figure(fid)。你可以在你的情况下使用getframe(fid)

标签: matlab loops object video frame


【解决方案1】:

我所要做的就是将hold offclose(writerObj) 行移到kk 循环之后。容易小便!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多