# I want to find event1 in my EEG data, followed by event2 and then extract reaction time between them

for i=1:length(subjects)
for k = 1:length(EEG.event)-1
disp(k);
if strcmp(EEG.event(k).type,con1)
k = k+1;
if strcmp(EEG.event(k+1).type,con2)
rt = EEG.event(k+1).latency-EEG.event(k).latency;
end
end
end
end

• Welcome. What are the events? How are they defined and what are their characteristics? More general information helps too - What was the experiment like? How many channels? What was the task, if any?
– AliceD
Sep 20 '18 at 10:10
• Thanks. There were two types of stimulus.stimulus1 followed by a response with no time limit. hence I have now data with 36 type1 stimulus,followed by their responses and same for type stimulus2. Total channels were 32. I am interested in retrieving the shortest reaction time between type1 stimulus and the response (same for type2 stimulus) and epoch the events based on this reaction time. Sep 20 '18 at 10:40
• And you know when these events happened? Or do you have to analyze the data to extract them?
– AliceD
Sep 20 '18 at 10:48
• No I don't know when these events happened. But for every event I have a trigger, based on them I need to extract event1 followed by its response and difference between their reaction time. Sep 20 '18 at 10:55
• This seems like more of a programming question, or a specific research question we can't really answer here: you need to decide what your response is before bothering to try to detect it. Sep 20 '18 at 14:43

I'm guessing you are using Matlab. Your code is mainly sound, but a few comments:

• don't use "i" or "j" as they are function names in Matlab.
• don't change the value of a for loop variable inside the loop.

Here is you code, corrected:

for sub=1:length(subjects)