function ymix = mixup(y,indices)
% This function accepts a vector $y$ of size 3^m1, for some m1, and a
% permutation $indices$ of size 3^m2, for m2 <= m1, and scrambles
% the 3^m2 subvectors of y (each of size 3^(m1-m2)) according to
% the permutation.

n = max(size(y)) / max(size(indices)) ;
m = round(log(n) / log(3)) ;

ymix = zeros(size(y)) ;
for i = 1:length(indices)
  ymix(mindices(i,m)) = y(mindices(indices(i),m)) ;
end