function seq=avi2matrix(filename,flag);
%avi2matrix
%
%   Usage: [seq]=avi2matrix(filename,flag);
%
%   Where
%        filename - avifile name
%        flag     - 0-Color 1-B/W [Default = 1]

avi=aviread(filename);
if nargin<2
    flag=1;
end

for i=1:size(avi,2)
    if (flag==0)
        seq(:,:,:,i)=avi(i).cdata;
    else
        seq(:,:,i)=rgb2gray(avi(i).cdata);
    end
end
