-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunBlock.m
164 lines (85 loc) · 4.52 KB
/
runBlock.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function [TrialSettings, Behav, Logs, BlockSettings] = runBlock(Settings, BlockSettings)
% INPUT
% blockType If 1 runs as free response block, if 2 runs a block with
% response at interogation time.
%% Set up
% Initialise
BlockSettings.DurationReasigns = 0;
BlockSettings.RefReassigns = 0;
% Give participant type of block, and instructions refresher
if BlockSettings.BlockType == 1
text4disp = ['This block is free response.' ...
'\n\nRemember, in this block you can respond whenever you like.' ...
'\nTry to be as fast and accurate as possible.' ...
'\n\nClick the mouse to begin.'];
elseif BlockSettings.BlockType == 2
text4disp = ['This block is a deadline block.' ...
'\n\nRemember, in this block you must respond when the red cross appears.' ...
'\n\nClick the mouse to begin.'];
end
Screen('TextSize', Settings.Win, Settings.Text.Size2);
DrawFormattedText(Settings.Win, text4disp, 'center', 'center', [255 255 255], 1000, 0, 0, 1.3);
Screen('Flip', Settings.Win);
waitForInput
%% Randomisation of trials to conditions
% Set the location of the high mean box
conditionOrder = randperm(Settings.BlockTrials);
stimLoc = mod(conditionOrder, 2) +1;
for iTrial = 1 : Settings.BlockTrials
TrialSettings(iTrial).StimLoc = stimLoc(iTrial);
end
% Set duration of trials. This will depend on the blockType
if BlockSettings.BlockType == 1
% Free resp block. Set maximum duration of trials to a very high number.
for iTrial = 1 : Settings.BlockTrials
TrialSettings(iTrial).FramesToPresent = 10 * 60 * Settings.Timing.Fps;
end
elseif BlockSettings.BlockType == 2
% Interrogation block. Randomise duration of trials.
for iTrial = 1 : Settings.BlockTrials
TrialSettings(iTrial).FramesToPresent = BlockSettings.MeanFrames + ...
round(randn(1) * BlockSettings.FramesSd);
% If this is above or below max and min values then reassign
while TrialSettings(iTrial).FramesToPresent < Settings.Timing.FramesMin || ...
TrialSettings(iTrial).FramesToPresent > Settings.Timing.FramesMax
BlockSettings.DurationReasigns = BlockSettings.DurationReasigns + 1;
TrialSettings(iTrial).FramesToPresent = BlockSettings.MeanFrames + ...
round(randn(1) * BlockSettings.FramesSd);
end
end
end
%% Other randomisation
% Randomly assign the number of dots that will be half way between the
% number of dots in the high mean and low mean dot clouds
for iTrial = 1 : Settings.BlockTrials
TrialSettings(iTrial).RefVal = round(randn(1)*Settings.Dots.RefSd) + Settings.Dots.RefMean;
% If this is above or below max and min values then reassign
while TrialSettings(iTrial).RefVal > Settings.Dots.RefMax || ...
TrialSettings(iTrial).RefVal < Settings.Dots.RefMin
BlockSettings.RefReassigns = BlockSettings.RefReassigns + 1;
TrialSettings(iTrial).RefVal = ...
round(randn(1)*Settings.Dots.RefSd) + Settings.Dots.RefMean;
end
end
%% Loop through trials and store results
for iTrial = 1 : Settings.BlockTrials
%run a trial...
[Behav(iTrial), Logs(iTrial), CurrentTrialSettings] = runTrial(Settings, BlockSettings, ...
TrialSettings(iTrial));
% Add information to TrialSettings
TrialSettings(iTrial).DotsSet1 = CurrentTrialSettings.DotsSet1;
TrialSettings(iTrial).DotsSet2 = CurrentTrialSettings.DotsSet2;
% While we are here, also compute and store the number of dots shown each frame.
TrialSettings(iTrial).Dots = [sum(TrialSettings(iTrial).DotsSet1, 1); ...
sum(TrialSettings(iTrial).DotsSet2, 1)];
% This array will now include the details of every frame that was prepared for flipping, but the
% final frame prepared may not have actually been displayed. If this is the case then trim the
% array.
if Behav(iTrial).FramesPresented == size(TrialSettings(iTrial).Dots, 2) -1
TrialSettings(iTrial).Dots(:, end) = [];
elseif Behav(iTrial).FramesPresented ~= size(TrialSettings(iTrial).Dots, 2)
save('errorData')
sca
error('Bug. See saved file ''errorData''')
end
end