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 16:57:45 +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

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

                 Summary: `num2str` produces different results in Octave and
in Matlab
                 Project: GNU Octave
            Submitted by: lmendo
            Submitted on: lun 28 dic 2015 16:57:44 GMT
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: Luis Mendo
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.0.0
        Operating System: Microsoft Windows

    _______________________________________________________

Details:

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 the
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]