title: How to re order the dimensions on n-dimensional matrix in C? (Similar to permute(A,[2:n 1]) in Matlab )
body: <p>I am working a n-dimensional matrix (which being stored as a single dimensional array), I wish to reorder in its dimensions such that the leading dimension is now the last dimension.</p>
  
  <blockquote>
    <p>eg. if Dimensions(A) = 3 x 4 x 5 x 6 , I would want to change it to 4 x 5 x 6 x 3. 
    This is similar to a transpose function for a 2-D matrix.</p>
  </blockquote>
  
  <p>It can be implemented using permute function in Matlab
  for n dimensional matrix A. I want the following tranformation</p>
  
  <pre><code>A=permute(A,[2:n 1])
  </code></pre>
  
  <p>How could I do it in C?</p>
  
  <p>P.S. I am not looking to reshape the matrix but to actually move the elements in order to get the next dimension as the leading dimension.</p>
  
  <p>Permute can be defined as </p>
  
  <pre><code>B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they
  %   are in the order specified by the vector ORDER.  The array produced
  %   has the same values as A but the order of the subscripts needed to 
  %   access any particular element are rearranged as specified by ORDER.
  %   For an N-D array A, numel(ORDER)&gt;=ndims(A). All the elements of 
  %   ORDER must be unique.
  </code></pre>