bugGNU Octave - Bugs: bug #55880, Octave does not allow reshaping...

 
 

bug #55880: Octave does not allow reshaping empty scalar struct to empty struct array (Matlab Compatibility)

Submitter:  A.R. Burgers <arb>
Submitted:  Sun 10 Mar 2019 09:26:01 PM UTC
   
 
Category:  Interpreter Severity:  1 - Wish
Priority:  3 - Low Item Group:  WTF, Matlab?!?
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 10 Mar 2019 09:59:06 PM UTC, comment #2: 

this script:


% script b55880.m
ver = version
s1 = reshape(struct(), 3, 1)
s2 = reshape(s1, 10, 1)
s3 = reshape(s1, 1, 10)

a.b = 1
a31 = reshape(a, 3, 1)


produces this:


ver =  '9.5.0.1049112 (R2018b) Update 3'

s1 =   3×1 struct array with no fields.
s2 =  10×1 struct array with no fields.
s3 =  1×10 struct array with no fields.

a =  struct with fields:
    b: 1

Error using reshape
To RESHAPE the number of elements must not change.

Error in b55880 (line 7)
a31 = reshape(a, 3, 1)


A.R. Burgers <arb>
Sun 10 Mar 2019 09:40:35 PM UTC, comment #1: 

Does that also work if the struct does have one or more fields? Or only for structs with no fields defined?


a.b = 1;
s = reshape(a, 3, 1)


Can the struct array be reshaped again?


s1 = reshape(struct(), 3, 1)
s2 = reshape(s1, 10, 1)
s3 = reshape(s1, 1, 10)


Using 'repmat' instead of 'reshape' is an easy workaround that also makes sense in this weird case.

Mike Miller <mtmiller>
Group Member
Sun 10 Mar 2019 09:26:01 PM UTC, original submission:  

matlab has a rather surprising, I think undocumented, way to create an array of empty structs:


struct_array = reshape(struct(), 3, 1)


matlab output:


struct_array = 3x1 struct array with no fields.


A.R. Burgers <arb>

 

(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 (Updated the item)
  • -email is unavailable- added by arb (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-10 rik5 StatusNone Confirmed
        Summaryoctave misses matlab (feature?) to create array of empty structs Octave does not allow reshaping empty scalar struct to empty struct array (Matlab Compatibility)
    2019-03-10 mtmiller Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility WTF, Matlab?!?

    Back to the top

    Powered by Savane 3.13-f762.
    Corresponding source code