Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

571 Add "from MATLAB Table" example to Dynamic Tables tutorial #604

Merged
merged 7 commits into from
Nov 1, 2024
5 changes: 4 additions & 1 deletion +tests/+system/DynamicTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ function toTableTest(testCase)
ExpectedSubTable = testCase.file.intervals_trials.getRow(1:20);
% convert DynamicTable to MATLAB table
TrialsTable = testCase.file.intervals_trials.toTable();
TrialsTable.id = []; %remove id column
% Remove id column and variable descriptions as they are not
% present in the ExpectedSubTable retrieved from getRow method
TrialsTable.id = [];
TrialsTable.Properties.VariableDescriptions = {};
% retrieve rows from MATLAB table
ActualSubTable = TrialsTable(1:20,:);
% compare
Expand Down
5 changes: 5 additions & 0 deletions +types/+util/+dynamictable/nwbToTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

% deal with DynamicTableRegion columns when index is false
[columns, remainingColumns] = deal(DynamicTable.colnames);
columnDescriptions = repmat({''}, 1, length(columns));

for i = 1:length(columns)
cn = columns{i};
Expand All @@ -61,6 +62,7 @@
else
cv = DynamicTable.vectordata.get(cn);
end
columnDescriptions{i} = cv.description;
if ~index && ...
(isa(cv,'types.hdmf_common.DynamicTableRegion') ||...
isa(cv,'types.core.DynamicTableRegion'))
Expand All @@ -85,3 +87,6 @@

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

% Add variable descriptions
matlabTable.Properties.VariableDescriptions = [{''}, columnDescriptions];
11 changes: 9 additions & 2 deletions +util/table2nwb.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if ismember('id', T.Properties.VariableNames)
id = T.id;
else
id = 0:height(T)-1;
id = transpose( 0:height(T)-1 ); % Must be column vector
end

nwbtable = types.hdmf_common.DynamicTable( ...
Expand All @@ -28,8 +28,15 @@

for col = T
if ~strcmp(col.Properties.VariableNames{1},'id')

if ~isempty(col.Properties.VariableDescriptions{1})
description = col.Properties.VariableDescriptions{1};
else
description = 'no description provided';
end

nwbtable.vectordata.set(col.Properties.VariableNames{1}, ...
types.hdmf_common.VectorData('data', col.Variables',...
'description', 'my description'));
'description', description));
end
end
Binary file modified tutorials/dynamic_tables.mlx
Binary file not shown.
81 changes: 58 additions & 23 deletions tutorials/html/dynamic_tables.html

Large diffs are not rendered by default.