Search code examples
matlabloopsmovie

Exporting movie from matlab


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


Solution

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