Skip to content

Commit 3ebcea0

Browse files
committed
adding event processing scripts
1 parent ad66a95 commit 3ebcea0

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

event_processing_single_dataset.m

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%% Working with events
2+
eeglab_path = fileparts(which('eeglab.m')); % get EEGLAB path
3+
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab; % start EEGLAB
4+
pop_editoptions( 'option_storedisk', 0); % Change option to process multiple datasets
5+
EEG = pop_loadset( 'eeglab_data.set', fullfile(eeglab_path, 'sample_data')); % load data
6+
7+
%% Adjust event latency
8+
for iEvent=1:length(EEG.event)
9+
EEG.event(iEvent).latency = EEG.event(iEvent).latency + 10;
10+
end
11+
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); % Store dataset
12+
13+
%% Add new cue events to a loaded dataset 0.1 second before time-locking event
14+
nevents = length(EEG.event);
15+
for index = 1 : nevents
16+
if ischar(EEG.event(index).type) && strcmpi(EEG.event(index).type, 'square')
17+
% Add events relative to existing events
18+
EEG.event(end+1) = EEG.event(index); % Add event to end of event list
19+
% Specifying the event latency to be 0.1 sec before the referent event (in real data points)
20+
EEG.event(end).latency = EEG.event(index).latency - 0.1*EEG.srate;
21+
EEG.event(end).type = 'cue'; % Make the type of the new event cue
22+
end
23+
end
24+
25+
EEG = eeg_checkset(EEG, 'eventconsistency'); % Check all events for consistency
26+
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); % Store dataset
27+
eeglab redraw % Redraw the main EEGLAB window

event_processing_study.m

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%% Scan all datasets in a study
2+
3+
% load the epoched tutorial dataset
4+
eeglab_path = fileparts(which('eeglab.m')); % get EEGLAB path
5+
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab; % start EEGLAB
6+
pop_editoptions( 'option_storedisk', 0); % Change option to process multiple datasets
7+
EEG = pop_loadset( 'eeglab_data_epochs_ica.set', fullfile(eeglab_path, 'sample_data')); % load data
8+
[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG);
9+
10+
% scan all datasets and modify events
11+
% there is only one here so it is for illustration purpose
12+
commands = {}; % for building the STUDY
13+
for iDat = 1:length(ALLEEG)
14+
for iEvent = 1:length(ALLEEG(iDat).event)-1
15+
curEvent = ALLEEG(iDat).event(iEvent); % current event
16+
nextEvent = ALLEEG(iDat).event(iEvent+1); % next event
17+
18+
% only find reaction time event following time-locking events (TLE) within the same epoch
19+
if strcmpi( curEvent.type, 'square') && strcmpi( nextEvent.type, 'rt') && nextEvent.epoch == curEvent.epoch
20+
ALLEEG(iDat).event(iEvent).rt = (nextEvent.latency - curEvent.latency)/ALLEEG(iDat).srate * 1000; % latency of reaction time in ms
21+
end
22+
23+
end
24+
% save dataset
25+
fileName = fullfile( ALLEEG(iDat).filepath, [ ALLEEG(iDat).setname(1:end-4) '_rtevents.set' ]);
26+
ALLEEG(iDat).saved = 'no';
27+
ALLEEG(iDat) = pop_saveset(ALLEEG, fileName);
28+
29+
% add to list of dataset to build STUDY
30+
if isempty( ALLEEG(iDat).subject), ALLEEG(iDat).subject = sprintf('S%2.2d', iDat); end % create subject name
31+
commands = { commands{:} 'index' iDat 'load' fileName 'subject' ALLEEG(iDat).subject };
32+
end
33+
34+
% create study
35+
[STUDY, ALLEEG] = std_editset( [], [], 'commands', commands,'updatedat','off' );
36+
CURRENTSTUDY = true;
37+
eeglab redraw
38+
39+
% Use menu item STUDY -> Select/Edit STUDY design then
40+
% under "Edit the independent variables for this design", press "New"
41+
% You should be able to select event field 'rt' for creating designs

0 commit comments

Comments
 (0)