We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fb87a6f commit 02967feCopy full SHA for 02967fe
inst/dbtable.m
@@ -435,6 +435,14 @@ function summary (this)
435
y = true;
436
endfunction
437
438
+ function st = table2struct(this)
439
+ names = this.Properties.VariableNames;
440
+ st = {};
441
+ for idx=1:numel(names)
442
+ st.(names{idx}) = this._data{idx};
443
+ endfor
444
+ endfunction
445
+
446
# head tail - create sub tables
447
function tdata = head(this, rows)
448
nrows = size(this, 1);
@@ -541,3 +549,10 @@ function summary (this)
541
549
%! assert(t.V1, V1);
542
550
%! assert(t.V2, V2);
543
551
552
+%!test
553
+%! V1 = [0;1;3];
554
+%! V2 = [2;4;6];
555
+%! t = dbtable(V1, V2);
556
+%! s = table2struct(t);
557
+%! assert(fieldnames(s), {'V1'; 'V2'});
558
+%! assert(s.V1, [0;1;3]);
0 commit comments