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:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Wont Fix Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  Closed
Release:  dev 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)

Wed 27 Feb 2019 10:27:28 PM UTC, comment #11: 

Closing as "Won't Fix".  Until the function is added to the public API there is no need to add it to Octave.

Rik <rik5>
Project Administrator
Wed 27 Feb 2019 10:08:09 PM UTC, comment #10: 

just to finish previous response:

struct2arry is in a shared path, so not obvious which toolbox it belongs to.  Running:

[flist,plist]=  matlab.codetools.requiredFilesAndProducts('struct2array.m')

produces a plist struct showing:

'MATLAB'        '9.5'
'Signal Processing Toolbox'        '8.1'

so, I can't test but best evidence appears that it is a minimally/undocumented part of the signal processing toolbox. no qualms here if it isn't included.

Nicholas Jankowski <nrjank>
Wed 27 Feb 2019 06:48:54 PM UTC, comment #9: 

It seems like the Octave maintainers are less inclined to add a function to Octave that isn't part of Matlab's public documented interface. Despite being very simple to implement, this utility function is not a documented public function and may not be part of a Matlab installation with no add-on toolboxes installed. Is there any further discussion to have or should we close this as won't fix?

Mike Miller <mtmiller>
Project Administrator
Mon 01 Oct 2018 04:43:13 PM UTC, comment #8: 

According to https://www.mathworks.com/matlabcentral/answers/357399-conversion-of-structure-to-double-in-r2017a, the function exists in ${matlabroot}/toolbox/shared/measure, whatever that directory is for. Agrees with output shown in comment #2. It's probably an undocumented utility function that is used internally by other Matlab functions but not meant for general consumption.

I found another link that suggests that the function is loaded into the path as a side effect of the Signal Processing Toolbox, but is not actually part of the toolbox. They also posted the complete text of the function copyrighted by MathWorks, very trivial. Not sharing the link to avoid tainting others.

Mike Miller <mtmiller>
Project Administrator
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

C:\Program Files\MATLAB\R2016b\toolbox\shared\measure\struct2array.m

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

rmpath ([matlabroot '\toolbox\XXXXXX'])

and then use

ver

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: 

>> which struct2array
C:\Program Files\MATLAB\R2016b\toolbox\shared\measure\struct2array.m

I don't know, is that a toolbox?

struct contains double entries that have different sizes:

>> clear x
x.a = 1;
x.b = magic (3);
y = struct2array (x)
Error using horzcat
Dimensions of matrices being concatenated are not consistent.

Error in struct2array (line 13)
a = [c{:}];

That last line I think explains most of the rest.

What about non-double entries?

>> clear x
x.a = 1;
x.b = {'Cell', 'Array'};
x.c = 2;
y = struct2array (x)
y =
  1×4 cell array
    [1]    'Cell'    'Array'    [2]

If you had strings is instead of cells it does:

>> clear x
>> x.a = 100;
>> x.b = ['Cell','Array'];;
>> x.c = 200;
>> y = struct2array (x)
y =
dCellArrayÈ

What is the shape of the resulting array?

>> clear x
x(1,1).a = 1;
x(1,2).a = 2;
x(2,1).a = 3;
x(2,2).a = 4;
y = struct2array (x)
size (y)
y =
     1     3     2     4
ans =
     1     4

but if they were 2x1 arrays:

>> clear x
x(1,1).a = [1;2];
x(1,2).a = [3;4];
x(2,1).a = [5;6];
x(2,2).a = [7;8];
y = struct2array (x)
size (y)
y =
     1     5     3     7
     2     6     4     8
ans =
     2     4

How are null values handled?

>> clear x
x(1).a = 1;
x(3).a = 3;
y = struct2array (x)
size (y)
y =
     1     3
ans =
     1     2

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

>> struct2array([])
Undefined function 'struct2cell' for input arguments of type 'double'.
Error in struct2array (line 10)
c = struct2cell(s);

>> struct2array(NaN)
Undefined function 'struct2cell' for input arguments of type 'double'.
Error in struct2array (line 10)
c = struct2cell(s);

>> clear x
>> x.a = [];
>> struct2array(x)
ans =
     []

>> x.a = [];
>> x.b = NaN;
>> struct2array(x)
ans =
   NaN

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?

which struct2array

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

clear x
x.a = 1;
x.b = magic (3);
y = struct2array (x)

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

clear x
x.a = 1;
x.b = {"Cell", "Array"};
x.c = 2;
y = struct2array (x)

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

clear x
x(1,1).a = 1;
x(1,2).a = 2;
x(2,1).a = 3;
x(2,2).a = 4;
y = struct2array (x)
size (y)

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

clear x
x(1).a = 1;
x(3).a = 3;
y = struct2array (x)
size (y)

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:
   
   
Comment:
   

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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-27 rik5 StatusNeed Info => Wont Fix
        Open/ClosedOpen => Closed
    2019-02-27 mtmiller Severity3 - Normal => 1 - Wish
        Priority5 - Normal => 3 - Low
        Item GroupMatlab Compatibility => Feature Request
        Release4.2.1 => dev
    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.5