function x = ff2n(n)
%FF2N   Two-level full-factorial design.
%   X = FF2N(N) creates a two-level full-factorial design, X.
%   N is the number of columns of X. The number of rows is 2^N.

%   B.A. Jones 2-17-95
%   Copyright 1993-2000 The MathWorks, Inc. 
%   $Revision: 2.6 $  $Date: 2000/05/26 17:28:56 $

rows = 2.^(n);
ncycles = rows;
group = zeros(rows,n);

for k = 1:n
   settings = (0:1);
   ncycles = ncycles/2;
   nreps = rows./(2*ncycles);
   settings = settings(ones(1,nreps),:);
   settings = settings(:);
   settings = settings(:,ones(1,ncycles));
   x(:,n-k+1) = settings(:);
end
