【问题标题】:Exporting movie from matlab从matlab导出电影
【发布时间】:2013-06-01 17:47:26
【问题描述】:

我正在尝试在 matlab 中制作电影。

for i=1:runs;
       for k=1:NO_TIMES
       B = 0;
       [conf dom_size] = conf_update_massmedia(time(k),conf);


       shortconf=conf(1:N);
       for j=1:N;
       sigma(j,1:N) = conf(1+(j-1)*N:j*N);
       end
    figure(1)
    imagesc(sigma);
    colorbar;
    set(gcf,'PaperPositionMode','auto');
    F(k)=getframe(gcf);
    end

end

movie2avi(F,'B=0.avi','Compression','none')

所以我的问题是我只从循环的最后一次运行中得到了一部电影,我试图移动这个数字的代码,但似乎没有任何效果,有没有人可以帮忙?

颇尔

【问题讨论】:

  • 那是因为F(k)=getframe(gcf)在内部循环内部,这意味着每次通过外部循环F都会被覆盖。

标签: matlab loops movie


【解决方案1】:

正如@tmpearce 提到的,问题是因为覆盖了F 矩阵。

我建议你:

  1. 已初始化您的 F 矩阵。
  2. 始终缩进代码以使其可读(例如,参见 here)。

这是百万种解决方案之一:

f_ind = 1; % Frame index.
F = zeros(runs * NO_TIMES, 1); % initialization of Frames matrix.
figure; % remove figure(1) from your inner loop haowever.
for i = 1:runs;
    for k = 1:NO_TIMES
        % ...
        F(f_ind)=getframe(gcf);
        f_ind = f_ind + 1;
    end
end

【讨论】:

    【解决方案2】:

    movie2avi 有点过时,并且在各种操作系统上挣扎。更好的选择是使用 VideoWriter 命令:

    vidObj = VideoWriter('B=0.avi');
    vidObj.FrameRate=23;
    open(vidObj);
    
    for i=1:runs;
       for k=1:NO_TIMES
          B = 0;
          [conf dom_size] = conf_update_massmedia(time(k),conf);
          shortconf=conf(1:N);
    
          for j=1:N;
             sigma(j,1:N) = conf(1+(j-1)*N:j*N);
          end
    
          figure(1)
             imagesc(sigma);
             colorbar;
             set(gcf,'PaperPositionMode','auto');
    
          F=getframe(gcf);
          writeVideo(vidObj,F);
        end
    end
    
    close(vidObj);
    

    【讨论】:

      猜你喜欢
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-13
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      相关资源
      最近更新 更多