% This function calculates the decision time (DT) and re-decision reaction
% time rRDT for a single subject, single trial. The code is agnostic to
% which subject or trial it is.
%
% Inputs:
%   js1[T]      Data with the joystick position for one subject, one trial.
%   inp1[T]     Visual input presented to the subject. 

function [rDT,rRDT] = SingleAll(js1,inp1)

% Set up a threshold for the decision
thres = 0.2;

% Find the decision time (DT) and re-decision time (RDT)
DT = find(js1<(-1+thres),1);
RDT = find(js1>(1-thres),1);

% Find the times in which the input actually switched
RST = find(inp1==1,1);

% Reaction time equals decision time
rDT = DT;
% Calculate redecision reaction time
rRDT = RDT - RST;

end