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 i


From: Luis Mendo
Subject: [Octave-bug-tracker] [bug #46770] `num2str` produces different results in Octave and in Matlab
Date: Mon, 28 Dec 2015 17:02:43 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36

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

Sorry, the message was cut. I'll try again:

I've noticed two differences in `num2str` between Octave in Matlab:

(1) 2D arrays are not displayed aligned by Octave, whereas Matlab right-aligns
columns. For example, consider the following code:


x = [1.1, 2.22, -3.3; 4, 5.5, 6];
fmt = '%.16g ';
y = num2str(x, fmt)


Octave output (columns are not aligned):


1.1 2.22 -3.3
4 5.5 6
+varbatim+

Matlab output (columns are right-aligned):


1.1 2.22 -3.3
  4  5.5    6


More details here, where I originally asked:
http://stackoverflow.com/q/34483961/2586922. I found a workaround when format
string contains a single formatting operator, but not in the general case.

(2) The behaviour for arrays with more than two-dimensions also differs.


x = [1:3; 4:6]; x = cat(3, x, x);
num2str(x, '%i ')


Octave output:


1 2 3
4 5 6
1 2 3
4 5 6


Matlab output:


1 2 3 1 2 3
4 5 6 4 5 6


It seems like Matlab collapses all dimensions beyond the first and then
applies the formatting. Not sure if this is documented behaviour, though.

    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Mensaje enviado vía/por Savannah
  http://savannah.gnu.org/




reply via email to

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