Coarse Grained Movies in MATLAB

AIM : Let say the aim is to prepare a movie of coarse grained description of the system. In this example the 2-dimensionl lattice has been divided into several sub-square lattices. Then depending on the order parameter values (average) in the sub-square lattices, the color has been chosen and finally each frame has been added using 'addframe'.


clear all;
close all;
aviobj = avifile('box_movie.avi','compression','None');
aviobj.KeyFramePerSec = 1;
fig = figure;
fid = fopen('fort.214');

nbox = 25;
nframes = 9900;

for i = 1:1:nframes

    A = fscanf(fid, '%g', [1 nbox]);

    if (i < 3500) && (mod(i,5) == 0)
   
% Draw smaller boxes
   
    xstart = 0;
    ystart = 0;

    xlen = 1;
    ylen = 1;
   
    rectangle('position', [xstart, ystart, xlen, ylen]);
    nx = floor(sqrt(nbox));
    ny = nx;
    dx = xlen/(nx);
    dy = ylen/(ny);

    count = 0;

    for i = 1:nx
        x = xstart + (i-1)*dx;
        for j = 1:ny
            count = count + 1;
            z = A(1,count);
            y = ystart + (j-1)*dy;
            h = rectangle('position', [x, y, dx, dy]);
            if (z==1)
               set(h,'FaceColor','b');
            else
               set(h,'FaceColor','r');
            end
        end
    end

    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
 end

 close(fig);
 aviobj = close(aviobj);


 
N.B.:  Finally compressed the videos using anyone of the following commands.

  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)