Skip to content

Commit

Permalink
Merge branch '597-nwb-to-table-bug' into 571-special-table-tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Sep 17, 2024
2 parents 9de705d + 30bbbfd commit 575f858
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions +types/+util/+dynamictable/nwbToTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%NWBTOTABLE converts from a NWB DynamicTable to a MATLAB table
%
% MATLABTABLE = NWBTOTABLE(T) converts object T of class types.core.DynamicTable
% into a MATLAB Tale
% into a MATLAB Table
%
% MATLABTABLE = NWBTOTABLE(T, INDEX) If INDEX is FALSE, includes rows referenced by a
% DynamicTableRegion as nested subtables
Expand Down Expand Up @@ -50,10 +50,10 @@
);

% deal with DynamicTableRegion columns when index is false
columns = DynamicTable.colnames;
i = 1;
while i < length(columns)
cn = DynamicTable.colnames{i};
[columns, remainingColumns] = deal(DynamicTable.colnames);

for i = 1:length(columns)
cn = columns{i};
if isprop(DynamicTable, cn)
cv = DynamicTable.(cn);
elseif isprop(DynamicTable, 'vectorindex') && DynamicTable.vectorindex.isKey(cn) % Schema version < 2.3.0
Expand All @@ -71,15 +71,17 @@
cv{r,1} = ref_table.getRow(row_idxs(r)+1);
end
matlabTable.(cn) = cv;
columns(i) = [];
remainingColumns(i) = [];
else
i = i+1;
% pass
end
end
% append remaining columns to table
% making the assumption that length of ids reflects table height
matlabTable = [matlabTable DynamicTable.getRow( ...
1:length(ids), ...
'columns', columns ...
'columns', remainingColumns ...
)];

% Update the columns order to be the same as the original
matlabTable = matlabTable(:, [{'id'}, columns]);

0 comments on commit 575f858

Please sign in to comment.