File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 3939
4040 names = fieldnames(astruct );
4141
42- if isscalar (s )
42+ if isscalar (astruct )
4343 values = struct2cell(astruct );
4444 t = dbtable (values{: }, ' VariableNames' , names ' );
4545 else
4646 values = astruct(: );
4747 values = struct2cell(values );
48- t = dbtable (values{: }, ' VariableNames' , names ' );
48+ values = values ' ;
49+ cols = {};
50+ for idx= 1 : size(values , 2 )
51+ v = values(: ,idx );
52+ cols{end + 1 } = v ;
53+ endfor
54+ t = dbtable (cols{: }, ' VariableNames' , names ' );
4955 endif
5056endfunction
5157
5763% ! assert(t.Properties.VariableNames, {'a', 'b'});
5864% ! assert(t.a, [1;2;3]);
5965
66+ % !test
67+ % ! s = struct('a', {[1;2;3]}, 'b', {[2;4;6]});
68+ % ! t = struct2dbtable(s);
69+ % ! assert(istable(t));
70+ % ! assert(size(t), [3 2]);
71+ % ! assert(t.Properties.VariableNames, {'a', 'b'});
72+ % ! assert(t.a, [1;2;3]);
73+
6074% !error <Not a struct> struct2dbtable(1);
6175
6276% !error <Not a struct> struct2dbtable('hello');
You can’t perform that action at this time.
0 commit comments