function U = powerset(S)
% POWERSET Create a set of all the subsets
% U = powerset(S)
% U{1} = [], U{1} = [S(1)], ..., U{2^n} = S

n = length(S);
%masks = bintab(n);
masks=mybin2dec(0:(2^n)-1, n);
T = cell(1,2^n);
for i=1:2^n
  T{i} = S(find(masks(i,:)));
  Tsize(i) = length(T{i});
end
% T has the sets in binary order
% U has the sets ordered by size
[junk,perm] = sort(Tsize);
for i=1:2^n
  U{i} = T{perm(i)};
end
