Skip to content

Commit 0a74bb6

Browse files
committed
correct () operation
1 parent b968992 commit 0a74bb6

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

inst/dbtable.m

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,8 @@
156156
endif
157157

158158
if nargin == 1
159-
# special handling here
160-
# TODO: we should probally use functions like struct2table and cell2table
161-
# so we dont need to handle these here
162-
if isstruct (varargin{1})
163-
# size(in, 2) = 1 ?
164-
#this._data = varargin{1};
165-
# get var names from the struct
166-
names = fieldnames(varargin{1});
167-
for idx = 1:length(names)
168-
this.Properties.VariableNames{end+1} = names{idx};
169-
v = varargin{1}.(names{idx});
170-
#if iscell(v)
171-
# v = v{:};
172-
#endif
173-
this._data2{end+1} = this.fromcell(v);
174-
endfor
175-
return;
176-
elseif isa (varargin{1}, "dbtable")
177-
#this._data = varargin{1}._data;
159+
# special handling for copy constructor
160+
if isa (varargin{1}, "dbtable")
178161
this._data2 = varargin{1}._data2;
179162
this.Properties = varargin{1}.Properties;
180163
return;
@@ -341,7 +324,7 @@ function disp (this)
341324
endif
342325
elseif !isempty(this.Properties.DimensionNames) && strcmp(this.Properties.DimensionNames{2}, n)
343326
# return all row data
344-
subs = substruct('()',{':'});
327+
subs = substruct('{}',{':'});
345328
val = subsref(this, subs);
346329
elseif this.getcolidx(n) != -1
347330
# check in variable names
@@ -356,7 +339,7 @@ function disp (this)
356339
else
357340
error("'%s' unknown property name", n);
358341
endif
359-
elseif s(1).type == "()" || s(1).type == "{}"
342+
elseif s(1).type == "{}"
360343
if numel(s(1).subs) == 1
361344
s(1).subs = {s(1).subs{:}, ':'};
362345
endif
@@ -371,6 +354,20 @@ function disp (this)
371354
if size(val) == [1 1]
372355
val = val{1};
373356
endif
357+
elseif s(1).type == "()"
358+
if numel(s(1).subs) == 1
359+
s(1).subs = {s(1).subs{:}, ':'};
360+
endif
361+
row = s(1).subs{1};
362+
col = s(1).subs{2};
363+
names = this.Properties.VariableNames(col);
364+
cval = this._data2(col);
365+
val = {};
366+
for idx=1:numel(cval)
367+
val{end+1} = cval{idx}(row,:);
368+
endfor
369+
370+
val = dbtable(val{:}, 'VariableNames', names');
374371
else
375372
error("unimplemented dbtable.subsref type");
376373
endif
@@ -446,7 +443,7 @@ function summary (this)
446443
rows = nrows;
447444
endif
448445
names = this.Properties.VariableNames;
449-
data = this.subsref(substruct('()', {1:rows, ':'}));
446+
data = this.subsref(substruct('{}', {1:rows, ':'}));
450447
tdata = dbtable(data{:}, 'VariableNames', names);
451448
endfunction
452449

@@ -458,7 +455,7 @@ function summary (this)
458455
rows = nrows - rows + 1;
459456
endif
460457
names = this.Properties.VariableNames;
461-
data = this.subsref(substruct('()', {rows:nrows, ':'}));
458+
data = this.subsref(substruct('{}', {rows:nrows, ':'}));
462459
tdata = dbtable(data{:}, 'VariableNames', names);
463460
endfunction
464461

0 commit comments

Comments
 (0)