-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_responses.m
35 lines (32 loc) · 1.19 KB
/
match_responses.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
function [buttonsamp,rt] = match_responses(stimsamp, buttonresp, resp, f, varargin )
if nargin == 6
minrt = varargin{1};
maxrt = varargin{2};
minrt = minrt*f; maxrt = maxrt*f;
elseif nargin == 4 % old definition
minrt = 0;
maxrt = f; % 1s
end
if strcmp(resp,'left')
resp2 = 'right';
else
resp2 = 'left';
end
buttonsamp = zeros(size(stimsamp ));
rt = zeros(size(stimsamp ));
for tt = 1:length(stimsamp ) % left button press to probe
bsamp = buttonresp.(resp)( (buttonresp.(resp) - stimsamp(tt))>=minrt & (buttonresp.(resp) - stimsamp(tt))<= maxrt);
bsamp2 = buttonresp.(resp2)( (buttonresp.(resp2) - stimsamp(tt))>=minrt & (buttonresp.(resp2) - stimsamp(tt))<= maxrt);
if ~isempty(bsamp) % only use first button press
if isempty(bsamp2) % no other button was pressed
buttonsamp(tt) = bsamp(1);
rt(tt) = (buttonsamp(tt) - stimsamp(tt))/f;
else % other button was pressed
if bsamp2(1) > bsamp(1) % incorrect button was pressed after correct
buttonsamp(tt) = bsamp(1);
rt(tt) = (buttonsamp(tt) - stimsamp(tt))/f;
end
end
end
end
% buttonsamp(buttonsamp == 0) = [];