-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenSeqTargetTrials.m
142 lines (100 loc) · 4.25 KB
/
GenSeqTargetTrials.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
iSubj = 1;
% fMRI
% LevelsForVisual = linspace(0.05, 0.6, 10);
LevelsForVisual = linspace(0.1, 1.5, 5);
% fMRI
%AttenuationRange = linspace(0.05, 0.4, 10)
% Behav
%AttenuationRange = linspace(0.05, 0.1, 10)
LevelsForAudio = 1:2:10;
TrialsPerLevel = 5;
% a typical block has X trials of a given type (A, V, AV) including X/4
% with a target
OneBlock = [ones(1,TrialsPerLevel) zeros(1,3*TrialsPerLevel)];
BlockTypes = 1:3;
Duration = length(LevelsForAudio)*length(BlockTypes)*length(OneBlock)*.63 + length(LevelsForAudio)*length(BlockTypes)*5
DurationTR = (Duration + Duration*10/100)/3
%% VISUAL
TrialsFinal = [2 0];
TrialTypes = [100 11; ...
200 11; ...
300 11];
% Cartesian product... Solution found online. Seems also possible to use the ALLCOMB function if it has been downloaded from mathworks exchange.
sets = {BlockTypes, LevelsForVisual};
[x y] = ndgrid(sets{:});
% List of all possible combinations and repeats the matrix by the amount of times per condition.
Conditions = [x(:) y(:)];
Conditions = Conditions(randperm(length(Conditions)),:);
for BlockIndex = 1:length(Conditions);
CurrentBlockType = Conditions(BlockIndex,1);
while 1
OneBlock = OneBlock(randperm(length(OneBlock)));
if all([...
isempty(strfind(num2str(OneBlock),num2str([1 1])));...
isempty(strfind(num2str(OneBlock),num2str([1 0 1])));...
isempty(strfind(num2str(OneBlock),num2str([1 0 0 1])))])
break;
end
end
CurentBlockContent = [OneBlock ; zeros(1, length(OneBlock))];
CurentBlockContent(:,OneBlock(1,:)==1) = ...
repmat(TrialTypes(CurrentBlockType,:)',1,(size(CurentBlockContent(:,OneBlock(1,:)==1),2) ));
CurentBlockContent(1,OneBlock(1,:)==0) = TrialTypes(CurrentBlockType,1);
CurentBlockContent = CurentBlockContent(:);
CurentBlockContent(CurentBlockContent==0) = [];
CurentBlockContent(CurentBlockContent==11,2) = Conditions(BlockIndex,2);
TrialsFinal = [TrialsFinal ; CurentBlockContent ; 0 0]; %#ok<AGROW>
end
for i = iSubj
mkdir(strcat('Subject_', num2str(i)))
cd(strcat('Subject_', num2str(i)));
TrialListFile = strcat('Trial_List_Subject_', num2str(i), '_Run_222.txt');
fid = fopen (TrialListFile, 'w');
for TrialInd = 1:length(TrialsFinal)
fprintf (fid, '%3.2f %3.2f\n', TrialsFinal(TrialInd,1), TrialsFinal(TrialInd,2) );
end
fclose (fid);
cd ..
end
%% AUDIO
TrialsFinal = [1 0];
TrialTypes = [100 10; ...
200 10; ...
300 10];
% Cartesian product... Also possible to use the ALLCOMB function from the mathworks exchange.
sets = {BlockTypes, LevelsForAudio};
[x y] = ndgrid(sets{:});
% List of all possible combinations and repeats the matrix by the amount of times per condition.
Conditions = [x(:) y(:)];
Conditions = Conditions(randperm(length(Conditions)),:);
for BlockIndex = 1:length(Conditions);
CurrentBlockType = Conditions(BlockIndex,1);
while 1
OneBlock = OneBlock(randperm(length(OneBlock)));
if all([...
isempty(strfind(num2str(OneBlock),num2str([1 1])));...
isempty(strfind(num2str(OneBlock),num2str([1 0 1])));...
isempty(strfind(num2str(OneBlock),num2str([1 0 0 1])))])
break;
end
end
CurentBlockContent = [OneBlock ; zeros(1, length(OneBlock))];
CurentBlockContent(:,OneBlock(1,:)==1) = ...
repmat(TrialTypes(CurrentBlockType,:)',1,(size(CurentBlockContent(:,OneBlock(1,:)==1),2) ));
CurentBlockContent(1,OneBlock(1,:)==0) = TrialTypes(CurrentBlockType,1);
CurentBlockContent = CurentBlockContent(:);
CurentBlockContent(CurentBlockContent==0) = [];
CurentBlockContent(CurentBlockContent==10,2) = Conditions(BlockIndex,2);
TrialsFinal = [TrialsFinal ; CurentBlockContent ; 0 0]; %#ok<AGROW>
end
TrialsFinal
for i = iSubj
cd(strcat('Subject_', num2str(i)));
TrialListFile = strcat('Trial_List_Subject_', num2str(i), '_Run_111.txt');
fid = fopen (TrialListFile, 'w');
for TrialInd = 1:length(TrialsFinal)
fprintf (fid, '%3.2f %3.2f\n', TrialsFinal(TrialInd,1), TrialsFinal(TrialInd,2) );
end
fclose (fid);
cd ..
end