Movies in Matlab: Addframe

2D movie of different types of particles, using 'gscatter' and 'addframe': MATLAB

Let say, the goal is to create a movie file from different snapshots and the available raw data has the co-ordinates and corresponding order parameters value. By the following way one will end up with a 2D video of (x,y) data having different types of particles characterized by 'z' values. The two key commands used are gscatter and addframe.

In this example all the particles are of two types, so I used two types of color function (blue and red) to distinguish them. Finally, I was looking to fill up the markers, however I could not find any suitable way to fill them (If anybody knows about it please let me know). Instead of searching for filling the markers I used a crude way of increasing linewidth of the markers, which eventually ended up, what I needed :). 
%To create movie from scatter plot
aviobj = avifile('movie.avi','compression','None');
fig=figure;
fid=fopen('movie.dat');
npart=240;
nframes = 1000;
for i=1:1:nframes
    A = fscanf(fid, '%g %g %g', [3 npart]);
    x=A(1,:);
    y=A(2,:);
    z=A(3,:);
    h1=gscatter(x,y,z,'br','o',5,'off',[],[]);
    set(h1,'LineWidth',5)
    box on;
    set(gca,'XTick',[],'YTick',[]);
    % for customized axis off, one can use the following
    %set(gca,'xcolor',get(gcf,'color'));   %to off x-coordinate
    %set(gca,'ycolor',get(gcf,'color'));   %to off y-coordinate
    F = getframe(fig);
    aviobj = addframe(aviobj,F);
 end
close(fig);
aviobj = close(aviobj);

 

N.B.: In linux machine there is no alternative 'compression' types available for MATLAB, and the uncompressed output file is huge in size. One can easily compressed the videos using several softwares. I generally prefer  to use anyone of the followings

  ffmpeg -i input.avi -vcodec msmpeg4v2 output.avi
or
  mencoder -idx input.avi -ovc lavc -oac mp3lame -o output.avi



Comments

Popular posts from this blog

VMD High Resolution Image and Movie

Inset Plot in GRACE (Xmgrace)