www.pudn.com > snippets(1).rar > frame2vec.m, change:2009-10-12,size:864b


function V = frame2vec(C,numf,datatype)
%
% reformat a cell array into a matrix, one column per NUMF frames

[d,v,s] = size(C);
[x,y,f] = size(C{1,1,1});

xy = x*y;
V = zeros(d*v*s*xy,f,datatype);
st = 1;
ed = xy;
for u = 1:d
  for v = 1:v
    for w = 1:s
      V(st:ed,:) = reshape(C{u,v,w},xy,f);
      st = st+xy;
      ed = ed+xy;
    end
  end
end

% stack desired number of frames
[ht,ln] = size(V);
for u = 2:numf
  H = V(1:ht,:);
  H = [H(:,u:end) zeros(ht,u-1,datatype)];
  V = [V ; H];
end

% remove orphan frames at the end
V = V(:,1:end+1-numf);

% $$$ 
% $$$ % stack desired number of frames
% $$$ ht = numf*size(V,1);
% $$$ sV2 = size(V,2);
% $$$ ln = floor(sV2/numf);
% $$$ 
% $$$ % make sure there are no orphan frames at the end
% $$$ modulo = mod(sV2,numf);
% $$$ if modulo~=0
% $$$   V = V(:,1:sV2-modulo);
% $$$ end
% $$$ V = reshape(V,ht,ln);