-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStroopTestNY.m
185 lines (149 loc) · 4.26 KB
/
StroopTestNY.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function trials = stroop(num, lang)
%STROOP The Stroop test
%
% SYNOPSIS
% trials = stroop();
% trials = stroop(num);
% trials = stroop(num, lang);
%
% INPUT
% num Number of trials {100}
% lang Language of experiment {en} | cs
% THIS IS ADAPTED FROM ONLINE
% User input
if nargin<=1, lang = 'en'; end;
if nargin<=0, num = 100; end;
% Load language
eval(['lang_' lang]);
COLORS = {'red', 'blue', 'green', 'cyan'};
KEYS = 'rbgc';
% Create Interface window
h = figure();
set(h, 'NumberTitle', 'off', ...
'Name', 'Stroop Test', ...
'Color', 'black', ...
'MenuBar','none', ...
'ToolBar', 'none');
% Display instruction
ht = show_text(h, lang.instructions, 'FontSize', 20);
waitforspace(h);
delete(ht);
% Session variables
ntrials = 0; % Number of trials already preformed
nmixed = 0; % Number of mixed trials
nerrors = 0; % Number of incorrect replies
trials = cell(0,4);
% Start test
while ntrials < num
% Chose between normal or mixed
mixed = rand() > (nmixed/(ntrials - nmixed))/2;
% Create trial
perm = randperm(4);
iStimul = perm(1);
iNoise = iif(mixed, perm(2), perm(1));
% Pause for 1 + (0-2) s and display
pause(0.5 + rand*2);
ht = show_text(h, lang.words(iNoise),...
'FontSize', 40,...
'ForegroundColor', lang.colors{iStimul});
tic;
% Wait for user input
waitforbuttonpress;
rtime = toc;
ch = get(h, 'CurrentCharacter');
delete(ht);
if ch == lang.keys(iStimul)
ntrials = ntrials + 1;
if mixed, nmixed = nmixed + 1; end;
ht = show_text(h, lang.correct, 'ForegroundColor', 'green', 'FontSize', 20);
else
% Check for unknown characters
nerrors = nerrors + 1;
ht = show_text(h, lang.incorrect, 'ForegroundColor', 'red', 'FontSize', 20);
end
% Store result
trials{end+1, 1} = iStimul;
trials{end, 2} = iNoise;
if length(find(lang.keys == ch)) > 0
trials{end, 3} = find(lang.keys == ch);
else
trials{end, 3} = 0;
end
trials{end, 4} = rtime;
% Show result for 0.5 s and continue
pause(0.5);
delete(ht);
end
% Some stats
fprintf('# correct trials: %d\n', ntrials);
fprintf('# mixed trials: %d\n', nmixed);
fprintf('ratio mixed/normal: %0.3f\n', nmixed/(ntrials-nmixed));
fprintf('# all trials: %d\n', size(trials, 1));
fprintf('# incorrect trials: %d\n', nerrors);
% Compute result
mixed = [trials{:,1}] ~= [trials{:,2}];
correct = [trials{:,1}] == [trials{:,3}];
bins = 0.2:0.2:3;
fDiffer = hist([trials{mixed & correct, 4}], bins);
fMatch = hist([trials{~mixed & correct, 4}], bins);
% Load data
if exist('stats.mat', 'file')
load('stats.mat');
FMatch = FMatch + fMatch;
FDiffer = FDiffer + fDiffer;
Count = Count + 1;
else
FMatch = fMatch;
FDiffer = fDiffer;
Count = 1;
end
% Save results
save('stats.mat', 'FMatch', 'FDiffer', 'Count');
% Show results
figure(h);
set(h, 'Color', 'white');
subplot(2,1,1);
bar(bins, [fMatch/sum(fMatch); fDiffer/sum(fDiffer)]');
title(lang.current_results);
xlabel(lang.xlabel);
ylabel(lang.ylabel);
legend(lang.label_agree, lang.label_differ);
subplot(2,1,2);
bar(bins, [FMatch/sum(FMatch); FDiffer/sum(FDiffer)]');
title(sprintf(lang.overall_results, Count));
xlabel(lang.xlabel);
ylabel(lang.ylabel);
legend(lang.label_agree, lang.label_differ);
end
function waitforspace(h)
waitforbuttonpress;
key = get(h, 'CurrentKey');
while ~strcmp(key, 'space')
waitforbuttonpress;
key = get(h, 'CurrentKey');
end
end
function handle = show_text(parrent, string, varargin)
parpos = get(parrent, 'Position');
pos = [5 round(parpos(4)/2)-30 parpos(3)-10 60];
handle = uicontrol(parrent,...
'Style','Text',...
'BackgroundColor', 'black',...
'ForegroundColor', 'white',...
'Position', pos,...
'FontUnits', 'pixels');
if length(varargin) > 0, set(handle, varargin{:}), end;
fontsize = get(handle, 'FontSize');
[outstring,newpos] = textwrap(handle,string);
height = length(outstring) * 1.1 * fontsize;
pos = [5 round(parpos(4)/2)-round(height/2) parpos(3)-10 height];
set(handle,'String',outstring,'Position', pos);
drawnow;
end
function ret = iif(test, valif, valelse)
if test
ret = valif;
else
ret = valelse;
end
end