|
| 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