Following code
x = [1.1, 2.22, -3.3; 4.44, 5.55, 6.6]; fmt = '%.16g '; y = num2str(x, fmt)
gives different results in Matlab (R20105b)
y = 1.1 2.22 -3.3 4.44 5.55 6.6
and in Octave (4.0.0)
y = 1.1 2.22 -3.3 4.44 5.55 6.6
The difference is alignment : in Matlab, the columns are right-aligned, while in Octave, they are not aligned.
I would like to achieve the exact Matlab behavior in Octave. Do you know any solution for this? Of course, I could write my own function, but maybe a solution already exists.
EDIT
Another difference is how multidimensional arrays are handled. For example,
x = cat(3, magic(3), -magic(3)); fmt = '%.16g '; y = num2str(x, fmt)
produces in matlab
y = 8 1 6 -8 -1 -6 3 5 7 -3 -5 -7 4 9 2 -4 -9 -2
and in octave
y = 8 1 6 3 5 7 4 9 2 -8 -1 -6 -3 -5 -7 -4 -9 -2
That is, Matlab joins 3D fragments along the second dimension, and Octave - along the first.
string printf matlab octave
Luis mendo
source share