octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #46770] num2str produces different results in


From: Rik
Subject: [Octave-bug-tracker] [bug #46770] num2str produces different results in Octave and in Matlab
Date: Mon, 28 Dec 2015 18:02:10 +0000
User-agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)

Follow-up Comment #4, bug #46770 (project octave):

There is another subtle difference.  Matlab is using a field width of 4.  You
can see that in the last column where there are two spaces between "5.55" and
"6.6".

A quick workaround in Octave is to use the specific format string that Matlab
must be using.


x = [1.1, 2.22, -3.3; 4.44, 5.55, 6.6];
fmt = '%4.16g ';
y = num2str(x, fmt)

y =

 1.1 2.22 -3.3
4.44 5.55  6.6


The underlying C libraries can't determine left/right justification if there
is no field width, because Octave also right justifies by default.  You can
see that by explicitly asking for left justification.


fmt = '%-4.16g ';
y = num2str(x, fmt)

y =

1.1  2.22 -3.3
4.44 5.55 6.6




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?46770>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]