Home > eeg > eeglab_petrmods > rename_events.m

rename_events

PURPOSE ^

EEG = rename_events(EEG, event_info);

SYNOPSIS ^

function EEG = rename_events(EEG, ei);

DESCRIPTION ^

 EEG = rename_events(EEG, event_info);

 Matches event codes in 'code' field of event_info with event codes in the 'type' field of the
 EEG.event structure (see EEGLAB for more info about the EEG structure), and
 replaces the value in the type field with the 'name' field in event_info

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function EEG = rename_events(EEG, ei);
0002 % EEG = rename_events(EEG, event_info);
0003 %
0004 % Matches event codes in 'code' field of event_info with event codes in the 'type' field of the
0005 % EEG.event structure (see EEGLAB for more info about the EEG structure), and
0006 % replaces the value in the type field with the 'name' field in event_info
0007 %
0008 
0009 % August 7, 2005 Petr Janata - initiated script
0010 
0011 nevents = length(ei);
0012 
0013 for ie = 1:nevents
0014   % Get a list of indices that match this event
0015   % How we do this depends on the variable types in event.type
0016   
0017   if any(cellfun('isclass',{EEG.event.type},'char'))
0018     event_idxs = find(ismember({EEG.event.type},num2str(ei(ie).code)));
0019   else
0020     event_idxs = find(ismember([EEG.event.type],ei(ie).code));
0021   end
0022   nidx = length(event_idxs);
0023   
0024   if nidx
0025     % Get the latencies and modify them so that they turn out right at the end of
0026     % the process
0027     tmp = num2cell([EEG.event(event_idxs).latency]/EEG.srate);
0028   
0029     % Create the newdata array
0030     clear newdata
0031     [newdata{1:nidx,1}] = deal(ei(ie).name);
0032     [newdata{:,2}] = deal(tmp{:});
0033   
0034     assignin('base','newdata',newdata);
0035     
0036     % Make the call to the EEGLAB function that will make the modificationss
0037     warning off
0038     EEG = pop_importevent(EEG,'event','newdata','indices',event_idxs, ...
0039     'fields',{'type','latency'},'append','yes');
0040     warning on
0041   end % if nidx
0042 end % for ie
0043 
0044 return

Generated on Tue 16-Jul-2019 04:00:51 by m2html © 2003