title: Convert R code into Matlab
body: <p>I need to write in Matlab this portion of the package "tensor" which is written in R. Unfortunately I am not used to R code style.  </p>
  
  <p>where <code>A=matrix(sample(0:1, 2 * 3, replace = TRUE), 2, 3)</code>
  here the code in R:</p>
  
  <pre><code>  A &lt;- as.array(A)
    dimA &lt;- dim(A)
    dnA &lt;- dimnames(A)      
  
    seqA &lt;- seq(along=dimA)
    allA &lt;- length(seqA) == length(alongA)
    permA &lt;- c(seqA[-alongA], alongA)
    if (!all(seqA == permA))
      A &lt;- aperm(A, permA)
    dim(A) &lt;- c(
      if (allA) 1 else prod(dimA[-alongA]),
      prod(dimA[alongA])
    )
  </code></pre>
  
  <p>Thank you in advance for your help!</p>