bugGNU Octave - Bugs: bug #60643, disp() for scalar struct not...

 
 

bug #60643: disp() for scalar struct not Matlab-compatible (displays object type)

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Wed 19 May 2021 11:18:04 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 28 May 2021 10:16:18 PM UTC, comment #5: 

Marking as Fixed and closing report.

Rik <rik5>
Group administrator
Tue 25 May 2021 04:17:08 PM UTC, comment #4: 

Was simple enough to fix once I found where the code was, but it took a while to find the code.  I checked in a change that makes Octave compatible with Matlab for the display of scalar structs in this changeset: http://hg.savannah.gnu.org/hgweb/octave/rev/777c16616c40.

Marking as Ready for Test.

Rik <rik5>
Group administrator
Fri 21 May 2021 10:25:26 PM UTC, comment #3: 

Confirmed.  Interestingly, Matlab and Octave both agree when the variable is a struct array.


abc = struct("foo","def","bar",1);
tmp(2) = abc;
disp (tmp)
  1x2 struct array containing the fields:

    foo
    bar


So, for a scalar struct the Octave should just go ahead and display the fields without the line


scalar structure containing the fields:


Rik <rik5>
Group administrator
Thu 20 May 2021 12:45:52 AM UTC, comment #2: 

also don't worry about the whitespace issues for octave, I have 'format compact' set as a default

Nicholas Jankowski <nrjank>
Group Member
Wed 19 May 2021 11:19:51 PM UTC, comment #1: 

sorry about title again:

should be 'struct disp not matlab compatible with object id header'

Nicholas Jankowski <nrjank>
Group Member
Wed 19 May 2021 11:18:04 PM UTC, original submission:  

Output from Matlab R2021a:

>> abc = struct("foo","def","bar",1)

abc =

  struct with fields:

    foo: "def"
    bar: 1

>> display(abc)

abc =

  struct with fields:

    foo: "def"
    bar: 1

>> disp(abc)
    foo: "def"
    bar: 1


with Octave 6.2.1 (hg id: 161daebce243)


>> abc = struct("foo","def","bar",1)
abc =

  scalar structure containing the fields:

    foo = def
    bar = 1

>> display(abc)
abc =

  scalar structure containing the fields:

    foo = def
    bar = 1

>> disp(abc)
  scalar structure containing the fields:

    foo = def
    bar = 1


the difference is disp, which still displays the object type and text for Octave. 

This came up when trying to overload display for a matlab-octave compatible class. here's a simple old class style example:


@MyClass/myClass.m:

function si = MyClass ()
  si = struct("foo","def","bar",1);
  si = class (si, 'MyClass');
end


with no display overloading:

Matlab:

>> A = MyClass

A =

       MyClass object: 1-by-1

>> A

A =

       MyClass object: 1-by-1

>> disp(A)
       MyClass object: 1-by-1

>> display(A)

A =

       MyClass object: 1-by-1


Octave:

>> A = MyClass
A =

  <class MyClass>

>> A
A =

  <class MyClass>

>> disp(A)
  <class MyClass>
>> display(A)
A =

  <class MyClass>


adding the following display overloading:

function display (obj)
  disp(sprintf('%s object containing the properties:', class(obj)))
  disp(struct(obj))
end


Matlab:

>> A = MyClass
MyClass object containing the properties:
    foo: "def"
    bar: 1

>> A
MyClass object containing the properties:
    foo: "def"
    bar: 1

>> disp(A)
       MyClass object: 1-by-1

>> display(A)
MyClass object containing the properties:
    foo: "def"
    bar: 1


Octave:

疘>> A = MyClass
MyClass object containing the properties:
  scalar structure containing the fields:

    foo = def
    bar = 1
>> A
MyClass object containing the properties:
  scalar structure containing the fields:

    foo = def
    bar = 1
>> disp(A)
  <class MyClass>
>> display(A)
MyClass object containing the properties:
  scalar structure containing the fields:

    foo = def
    bar = 1


Nicholas Jankowski <nrjank>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by nrjank (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-05-28 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2021-05-25 rik5 StatusConfirmed Ready For Test
    2021-05-21 rik5 StatusNone Confirmed
        Release6.2.0 dev
        Summarystruct disp not matlab compatible with object id header disp() for scalar struct not Matlab-compatible (displays object type)
    2021-05-20 siko1056 Summarystruct disp and display struct disp not matlab compatible with object id header

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code