function iout=natrixindexdecomposemy(ind,sz);
  ## natrix is a general dimensional matrix with arbitrary dimensions
  ## and size sz. 
  ## Ind may be a number, or more generally be a column vector.
  ## Anyhow, assume that ind is a single number which indices the matrix(:).
  ## IOUT is then the vector of the individual components corresponding
  ## to the index.
  ## For example:
  ## For a 2x2 matrix, ind=2 maps to iout=[2 1], and ind=3 to iout=[1
  ## 2].
  ##  For example, try natrixindicesdecomposemy(1:12,[2 2 3]) to see an
  ##  interesting numbers table. 

  ind=ind(:);
  
  l=length(sz);
  iout=zeros(length(ind),length(sz));

  ir=ind-1; ## index remaining.
  for ii=1:l;
    iout(:,ii)=1+mod(ir,sz(ii));
    ir=floor(ir/sz(ii));
  endfor
endfunction



  
