0
$\begingroup$
for i=1:length(subjects)
    EEG = pop_loadset([sub_name{i},'.set'],folder);
    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   
$\endgroup$
  • 1
    $\begingroup$ 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? $\endgroup$ – AliceD Sep 20 '18 at 10:10
  • $\begingroup$ 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. $\endgroup$ – Bubbles Sep 20 '18 at 10:40
  • $\begingroup$ And you know when these events happened? Or do you have to analyze the data to extract them? $\endgroup$ – AliceD Sep 20 '18 at 10:48
  • $\begingroup$ 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. $\endgroup$ – Bubbles Sep 20 '18 at 10:55
  • 2
    $\begingroup$ 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. $\endgroup$ – Bryan Krause Sep 20 '18 at 14:43
1
$\begingroup$

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)
    EEG = pop_loadset([sub_name{sub},'.set'],folder);
    trial = 0;
    for eve = 1:length(EEG.event)
        if strcmp(EEG.event(trial).type,con1)
            trial = trial+1;
            trialonset(trial) = EEG.event(trial).latency;
        elseif strcmp(EEG.event(trial).type,con2)
            trialoffset(trial) = EEG.event(trial).latency; 
        end
    end
    rtlist{sub} = trialoffset-trialonset;
end
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.