title: Achieve Matlab's `num2str` behaviour in Octave
body: <p>The following code</p>
  
  <pre><code>x = [1.1, 2.22, -3.3; 4.44, 5.55, 6.6];
  fmt = '%.16g ';
  y = num2str(x, fmt)
  </code></pre>
  
  <p>produces different results in Matlab (R20105b)</p>
  
  <pre><code>y =
   1.1 2.22 -3.3
  4.44 5.55  6.6
  </code></pre>
  
  <p>and in Octave (4.0.0)</p>
  
  <pre><code>y =
  1.1 2.22 -3.3
  4.44 5.55 6.6
  </code></pre>
  
  <p>The difference is the <strong>alignment</strong>: in Matlab the columns are right-aligned, whereas in Octave they are not aligned.</p>
  
  <p>I'd like to achieve exactly Matlab's behaviour in Octave. Do you know any solution for this? Of course I could write my own function, but maybe there already exists a solution.</p>
  
  <p><em>EDIT</em></p>
  
  <p>Another difference is how <strong>multidimensional arrays</strong> are treated. For example, </p>
  
  <pre><code>x = cat(3, magic(3), -magic(3));
  fmt = '%.16g ';
  y = num2str(x, fmt)
  </code></pre>
  
  <p>produces in Matlab</p>
  
  <pre><code>y =
  8  1  6 -8 -1 -6
  3  5  7 -3 -5 -7
  4  9  2 -4 -9 -2
  </code></pre>
  
  <p>and in Octave</p>
  
  <pre><code>y =
  
  8 1 6
  3 5 7
  4 9 2
  -8 -1 -6
  -3 -5 -7
  -4 -9 -2
  </code></pre>
  
  <p>That is, Matlab attaches the 3D slices along the second dimension, and Octave along the first.</p>