function [Y,U,V]=yuvread(filename,st,n)


if nargin<3
    n=input('How many frames you want to read in [all]? n=');
end
if nargin<2
    st=input('Pls provide the starting frame to read [1]:');
    if isempty(st),st=1; end
end

fmt=filename(length(filename)-3:length(filename));
switch lower(fmt)
    case '_cif'
        R=288; C=352;
    case '_sif'
        R=240; C=352;
    case 'qcif'
        R=144; C=176;
    case 'qsif'
        R=120; C=176;
    otherwise
        fmt=input('Pls give the sequence format(cif/sif/qcif/qsif/[ others give R and C]),fmt=','s');
        fmtarray={'cif','sif','qcif','qsif'};
        flag=strcmpi(fmtarray,fmt);
        if flag==0
            R=input('Pls give the ROW of one frame,R=');
            C=input('Give the column of one frame,C=');
        else
            switch lower(fmt)
                case 'cif'
                    R=288; C=352;
                case 'sif'
                    R=240; C=352;
                case 'qcif'
                    R=144; C=176;
                otherwise
                    R=120; C=176;
            end
        end
end

fid = fopen(filename,'r');
fseek(fid,0,'eof');
if isempty(n)
    n = ftell(fid)/(1.5*R*C);                   % frame numbers of the file
end

for i = st-1 : st+n-2
    fseek(fid,i*R*C*1.5,'bof');                 % positioning for every frame
                                                % read 3 channels data from file                                               
    Y(:,:,i+2-st) = double((fread(fid,[C,R],'uchar'))');
    U(:,:,i+2-st) = double((fread(fid,[C/2,R/2],'uchar'))');
    V(:,:,i+2-st) = double((fread(fid,[C/2,R/2],'uchar'))');  
end
fclose(fid);