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


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

Submitted by:  Nicholas Jankowski <nrjank>
Submitted on:  Thu 23 Mar 2017 11:08:12 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Need Info Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  Open
Release:  4.2.1 Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

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


( Jump to the original submission)

Mon 27 Mar 2017 05:49:16 PM UTC, 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 27 Mar 2017 05:22:07 PM UTC, 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 27 Mar 2017 04:15:29 PM UTC, comment #5:

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

Guillaume <gyom>
Sun 26 Mar 2017 12:12:37 AM UTC, 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 25 Mar 2017 05:25:32 PM UTC, 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 25 Mar 2017 04:24:35 AM UTC, 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 24 Mar 2017 10:59:37 PM UTC, 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 23 Mar 2017 11:08:12 PM UTC, 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 Files:

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


Depends on the following items: None found

Items that depend on this one: None found


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

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

    Only project members can vote.




    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-03-27 rik5 StatusNone => Need Info
    2017-03-25 nrjank Attached File- => Added struct2array.m, #40121
        Attached File- => Added add_struct2array_v2.diff, #40122
    2017-03-23 nrjank Attached File- => Added add_struct2array.diff, #40107
    2017-03-23 nrjank Attached File- => Added struct2array.m, #40106

    Back to the top

    Powered by Savane 3.3