bugGNU Octave - Bugs: bug #50622, missing function struct2array...


bug #50622: missing function struct2array (mainly structtocell wrapper)

Submitted by:  Nicholas Jankowski <nrjank>
Submitted on:  Thu Mar 23 23:08:12 2017  
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: Need InfoAssigned to: None
Originator Name: Nicholas JankowskiOpen/Closed: Open
Release: 4.2.1Operating System: Any

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


(Jump to the original submission Jump to the original submission)

Mon Mar 27 17:49:16 2017, comment #7:

Is the real issue that this function is not part of core Matlab, but resides in a toolbox?

I checked the thread pointed to by Nick and while they are running the exact same version of Matlab, they have different toolboxes installed.

Also, the path returned by which

really seems to imply that this is not a core Matlab function.

@Nick: Can you disable toolboxes in 2016b and try 'which struct2array.m' again?

I don't know if there is an easy click-box to temporarily disable a toolbox. If necessary, you could remove them from the path with

and then use

to check that they are indeed not listed.

Rik <rik5>
Project Administrator
Mon Mar 27 17:22:07 2017, comment #6:

I'm using Matlab 2016b, and did my compatibility testing against that.

I saw one mathworks newsgroup thread [1] (maybe you saw the same) where two people with 2014b reported getting found and not found responses to a 'which struct2array' query. Was it maybe left out of a version then put back in? Obviously with the lack of documentation that would be tough to track.

in any case, it's a trivial function, it's input/output hasn't changed in a decade, it appears present in 2016b, and was easy enough to implement. it's here if people choose to include it in a future version of octave.

[1] http://www.mathworks.com/matlabcentral/newsreader/view_thread/337858

Nicholas Jankowski <nrjank>
Mon Mar 27 16:15:29 2017, comment #5:

struct2array is not available in recent Matlab versions (it seems to have been removed in R2013b or R2014a).

Guillaume <gyom>
Sun Mar 26 00:12:37 2017, comment #4:

Yes, I noticed the same thing. Caught my attention when someone called out an Octave incompatibility. Looking into it it's been a part of matlab since at least 2004.

Generally ignore undocumented stuff, but implementation was pretty trivial so I threw the function together.

Nicholas Jankowski <nrjank>
Sat Mar 25 17:25:32 2017, comment #3:

The lack of documentation from this function, suggests that it's meant as private. The whole documentation of the function is "Convert structure with doubles to an array". And it doesn't even show up on their online help.

Carnë Draug <carandraug>
Project Member
Sat Mar 25 04:24:35 2017, comment #2:

I don't know, is that a toolbox?

struct contains double entries that have different sizes:

That last line I think explains most of the rest.

What about non-double entries?

If you had strings is instead of cells it does:

What is the shape of the resulting array?

but if they were 2x1 arrays:

How are null values handled?

Realize I didn't test for NAN, empty's etc., which seem to be popping up recently:

added these as tests to the function. updated m-file and patch attached.

(file #40121, file #40122)

Nicholas Jankowski <nrjank>
Fri Mar 24 22:59:37 2017, comment #1:

Can you check whether struct2array is in core Matlab or only in a toolbox by running the following in Matlab?

Also, what does Matlab do if the struct contains double entries that have different sizes?

What about non-double entries? Does it ignore them, produce an error, something else? Here is some test code

What is the shape of the resulting array? Does it mirror the input struct or is it something different?

How are null values handled? Are they converted to 0 or skipped?

Rik <rik5>
Project Administrator
Thu Mar 23 23:08:12 2017, original submission:

Saw on Stackexchange today that matlab has long had a poorly documented (but not completely undocumented. it shows up in help.) function struct2array that is the equivalent of flattening the output of struct2cell.

I wrote a quick function to implement this and it seems compatible with the matlab 2016b version including some input/output error testing.

M file is attached here. will attach a patch after this generates a bug number.

Nicholas Jankowski <nrjank>


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

Attach File(s):

Attached Files
file #40121:  struct2array.m added by nrjank (3kB - application/octet-stream - version 2, more tests)
file #40122:  add_struct2array_v2.diff added by nrjank (5kB - application/octet-stream - version 2, more tests)
file #40107:  add_struct2array.diff added by nrjank (4kB - application/octet-stream - changeset, including mfile, doc, module.mk, and news)
file #40106:  struct2array.m added by nrjank (2kB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by gyom (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by nrjank (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon Mar 27 17:49:16 2017rik5StatusNone=>Need Info
    Sat Mar 25 04:24:35 2017nrjankAttached File-=>Added struct2array.m, #40121
      Attached File-=>Added add_struct2array_v2.diff, #40122
    Thu Mar 23 23:24:18 2017nrjankAttached File-=>Added add_struct2array.diff, #40107
    Thu Mar 23 23:08:12 2017nrjankAttached File-=>Added struct2array.m, #40106

    Back to the top

    Powered by Savane 3.1-cleanup1