Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/readAndFilterLogfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
for iField = 1:numel(listFields)
output.(listFields{iField})(~filterIdx) = [];
end

output = convertStruct(output);

% Convert the structure to dataset
try
Expand All @@ -79,3 +81,21 @@
end

end

function structure = convertStruct(structure)
% changes the structure
%
% from struct.field(i,1) to struct(i,1).field(1)

fieldsList = fieldnames(structure);
tmp = struct();

for iField = 1:numel(fieldsList)
for i = 1:numel(structure.(fieldsList{iField}))
tmp(i,1).(fieldsList{iField}) = structure.(fieldsList{iField})(i,1);
end
end

structure = tmp;

end
4 changes: 0 additions & 4 deletions src/subfun/utilsForTests/setUp.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

function [cfg, logFile] = setUp()

outputDir = fullfile(fileparts(mfilename('fullpath')), 'output');

cfg.verbose = true;

cfg.subject.subjectNb = 1;
cfg.subject.runNb = 1;

cfg.task.name = 'testtask';

cfg.dir.output = outputDir;

cfg.testingDevice = 'mri';

cfg = createFilename(cfg);
Expand Down
19 changes: 18 additions & 1 deletion tests/test_readAndFilterLogfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
function test_readAndFilterLogfileBasic()

%% set up

cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output');
[cfg, logFile] = setUp();

% create the events file and header
Expand All @@ -29,6 +29,20 @@ function test_readAndFilterLogfileBasic()
logFile(end, 1).Speed = 2;
logFile(end, 1).is_Fixation = true;
logFile(end, 1).LHL24 = 2:13;

logFile(3, 1).onset = 2;
logFile(end, 1).trial_type = 'motion_up';
logFile(end, 1).duration = 3;
logFile(end, 1).Speed = 2;
logFile(end, 1).is_Fixation = true;
logFile(end, 1).LHL24 = 1:12;

logFile(4, 1).onset = 2;
logFile(end, 1).trial_type = 'motion_down';
logFile(end, 1).duration = 3;
logFile(end, 1).Speed = 2;
logFile(end, 1).is_Fixation = true;
logFile(end, 1).LHL24 = 2:13;

logFile = saveEventsFile('save', cfg, logFile);

Expand All @@ -48,8 +62,11 @@ function test_readAndFilterLogfileBasic()
assertEqual(exist(expectedFile, 'file'), 2);

content = bids.util.tsvread(expectedFile);

assertEqual(size(content.trial_type), [2, 1]);

assertEqual(content.trial_type{1}, 'motion_down');
assertEqual(content.trial_type{2}, 'motion_down');

end

Expand Down