Pergunta

I am trying to make a movie in 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')

So my problem is that i only get a movie from the last run of the loop, i have tried to move the code for the figure around, but nothing seems to work, is there anyone who are able to help?

Pall

Foi útil?

Solução 2

movie2avi is a little outdated and struggles on various operating systems. A better option is using the VideoWriter command:

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);

Outras dicas

As @tmpearce mentioned, the problem is because of overwriting the F matrix.

I suggest you to:

  1. Initialized your F matrix.
  2. Always indent you code to make it readable (see here for example).

This is one of the million solutions:

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top