Skip to content

Commit d332562

Browse files
authored
Merge pull request #107 from Remi-Gau/remi-change_read_filter_save
[FIX] make data saving after filtering all the relevant lines #105
2 parents e82e0db + 52f3039 commit d332562

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/readAndFilterLogfile.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
for iField = 1:numel(listFields)
6464
output.(listFields{iField})(~filterIdx) = [];
6565
end
66+
67+
output = convertStruct(output);
6668

6769
% Convert the structure to dataset
6870
try
@@ -79,3 +81,21 @@
7981
end
8082

8183
end
84+
85+
function structure = convertStruct(structure)
86+
% changes the structure
87+
%
88+
% from struct.field(i,1) to struct(i,1).field(1)
89+
90+
fieldsList = fieldnames(structure);
91+
tmp = struct();
92+
93+
for iField = 1:numel(fieldsList)
94+
for i = 1:numel(structure.(fieldsList{iField}))
95+
tmp(i,1).(fieldsList{iField}) = structure.(fieldsList{iField})(i,1);
96+
end
97+
end
98+
99+
structure = tmp;
100+
101+
end

src/subfun/utilsForTests/setUp.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
function [cfg, logFile] = setUp()
44

5-
outputDir = fullfile(fileparts(mfilename('fullpath')), 'output');
6-
75
cfg.verbose = true;
86

97
cfg.subject.subjectNb = 1;
108
cfg.subject.runNb = 1;
119

1210
cfg.task.name = 'testtask';
1311

14-
cfg.dir.output = outputDir;
15-
1612
cfg.testingDevice = 'mri';
1713

1814
cfg = createFilename(cfg);

tests/test_readAndFilterLogfile.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
function test_readAndFilterLogfileBasic()
1010

1111
%% set up
12-
12+
cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output');
1313
[cfg, logFile] = setUp();
1414

1515
% create the events file and header
@@ -29,6 +29,20 @@ function test_readAndFilterLogfileBasic()
2929
logFile(end, 1).Speed = 2;
3030
logFile(end, 1).is_Fixation = true;
3131
logFile(end, 1).LHL24 = 2:13;
32+
33+
logFile(3, 1).onset = 2;
34+
logFile(end, 1).trial_type = 'motion_up';
35+
logFile(end, 1).duration = 3;
36+
logFile(end, 1).Speed = 2;
37+
logFile(end, 1).is_Fixation = true;
38+
logFile(end, 1).LHL24 = 1:12;
39+
40+
logFile(4, 1).onset = 2;
41+
logFile(end, 1).trial_type = 'motion_down';
42+
logFile(end, 1).duration = 3;
43+
logFile(end, 1).Speed = 2;
44+
logFile(end, 1).is_Fixation = true;
45+
logFile(end, 1).LHL24 = 2:13;
3246

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

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

5064
content = bids.util.tsvread(expectedFile);
65+
66+
assertEqual(size(content.trial_type), [2, 1]);
5167

5268
assertEqual(content.trial_type{1}, 'motion_down');
69+
assertEqual(content.trial_type{2}, 'motion_down');
5370

5471
end
5572

0 commit comments

Comments
 (0)