function [outs] = ind2subT(sz,ndx)
  if length(siz)<=nout,
  siz = [siz ones(1,nout-length(siz))];
  else
    siz = [siz(1:nout-1) prod(siz(nout:end))];
end
n = length(siz);
k = [1 cumprod(siz(1:end-1))];
outs = zeros(1,nout);
for i = n:-1:1,
	  vi = rem(ndx-1, k(i)) + 1;         
vj = (ndx - vi)/k(i) + 1; 
outs(i) = vj; 
ndx = vi;     
end
