# Averaging multiple event classes in mne\_process\_raw

**URL:** <https://mne.discourse.group/t/averaging-multiple-event-classes-in-mne-process-raw/322>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [June 15, 2011, 8:46pm UTC](https://mne.discourse.group/t/averaging-multiple-event-classes-in-mne-process-raw/322 "2011-06-15T20:46:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [June 15, 2011, 8:46pm UTC](https://mne.discourse.group/t/averaging-multiple-event-classes-in-mne-process-raw/322/1 "2011-06-15T20:46:35Z")

</div>

Hello All,

&nbsp;&nbsp;&nbsp;&nbsp;My apologies if this question has been posted before. I would like to  
create an average of the epochs from several different stimulus conditions  
in my experiment. Unfortunately I did not have the foresight to specify a  
single trigger bit that would achieve the desired combination, and the  
"ignore" mask will not serve either. (The decimal triggers, are 1, 4, 7, and  
8, but I need to exclude 10.) The 2.7.3 manual mentions being able to  
include multiple events into an average (sect. 4.13.3, pg 79, new text in  
the uppermost change bar under "events" heading). However, I do not seem to  
be able to make this feature work. I have tried including multiple "event"  
lines in my category block, including the multiple codes (with and without  
comma separators) on a single event line, and adding the codes together (20)  
as is suggested by the sample.ave file from the median nerve example.

&nbsp;&nbsp;&nbsp;&nbsp;Has anyone else had this problem? Thanks in advance,

Per Lysne  
MIND Research Network/University of New Mexico  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20110615/ebc4012a/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20110615/ebc4012a/attachment.html)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [June 16, 2011, 2:44pm UTC](https://mne.discourse.group/t/averaging-multiple-event-classes-in-mne-process-raw/322/2 "2011-06-16T14:44:11Z")

</div>

Hi Per,  
It is very simple, copy matlab file below, and use it to create new event  
file, it can merge the events you want. You can then use this new event  
file for averaging. Code requires MNE matlab toolbox in the path.  
Fell free if you have any questions.

Sheraz Khan  
Martinos center

%---------------------------------------------------------------------------  
function newfile=mergeEvents(eventfile,orignalevents,newevents)

% mergeEvents: Merge Event in the event file  
%  
% USAGE: newfile=mergeEvents(eventfile,orignalevents,newevents)  
%  
% INPUT:  
% eventfile = Orignal Event File  
% orignalevents= Structure containg orignal event you want to merge  
% newevents= Number of the new events  
% OUTPUT:  
% newfile= New Event file Name  
% Example Use  
% orignalevents{1}=[1 2 3];  
% orignalevents{2}=[4 5];  
% newevents(1)=[997]  
% newevents(2)=[998]  
%  
newfile=mergeEvents('Orignal\_eventfile-eve.fif',orignalevents,newevents)  
% This code will merge events 1, 2 ,3 to event 997' and 4 , 5 to 998  
%  
% Author: Sheraz Khan, PhD  
% Martinos Center  
% MGH, Boston, USA  
% sheraz at nmr.mgh.harvard.edu  
% --------------------------- Script History ------------------------------  
% SK 19-Nov-2010 Creation  
% -------------------------------------------------------------------------

if size(orignalevents,2)~=length(newevents)  
&nbsp;&nbsp;&nbsp;&nbsp;error('both need to be same')  
end

[eventlist] = mne\_read\_events(eventfile);  
eventlist\_temp = eventlist;

for i=1:size(orignalevents,2)

events=orignalevents{i};  
for j=1:length(events)  
&nbsp;&nbsp;&nbsp;&nbsp;eventlist(eventlist==events(j))=newevents(i);

end  
end  
eventlist=[eventlist\_temp;eventlist];

temp = regexp(eventfile,'.fif');  
name = eventfile(1:temp-1);  
newfile=strcat(name,'\_merg-eve','.fif');

mne\_write\_events(newfile,eventlist)

%---------------------------------------------------------------------------
