octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #50622] missing function struct2array (mainly


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #50622] missing function struct2array (mainly structtocell wrapper)
Date: Sat, 25 Mar 2017 00:24:35 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0

Follow-up Comment #2, bug #50622 (project octave):


>> 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)
    _______________________________________________________

Additional Item Attachment:

File name: struct2array.m                 Size:2 KB
File name: add_struct2array_v2.diff       Size:4 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50622>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]