<div dir="ltr">Dear James,<div><br></div><div>Ah ok... but looks like eeg_addnewevets() internally uses loop.</div><div>My point is this: as far as I know, this is the only way to enter multiple variables to the multiple 'slots' in a structure.</div><div><br></div><div><div style="font-size:12.8000001907349px">> [EEG.event(1,1:length(allEventLabels)).latency] = allEventLatency{:};</div></div><div><br></div><div>Actually, I don't think it is necessary to exclude for loop this much. But, if you are dealing with large number of events (for example, saccade onset and offset for 1.5 hours of recording... it produced >50k events) this may make a difference.<br></div><div><br></div><div>Makoto</div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Sat, Feb 7, 2015 at 7:51 AM, James Desjardins <span dir="ltr"><<a href="mailto:jdesjardins@brocku.ca" target="_blank">jdesjardins@brocku.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<div>
<div style="direction:ltr;font-family:Tahoma;color:rgb(0,0,0);font-size:10pt">Hi Makoto! what is that?? :)<br>
<div><br>
I think that the "eeg_addnewevents" that Tarik brought up is the most elegant way of doing this without a loop at the command line (and I am going to use it from now on instead of those explicit loops).<br>
<br>
e.g.<span><br>
<br>
%Get the latencies (data point indices) for all 'A' type events...<br>
A_latencies=[EEG.event(find(strcmp('A',{EEG.event.type}))).latency];<br>
<br>
<font face="Courier New">%for each A_latencies add a new event type '1' with a latency of
</font><font face="Courier New"><font face="Courier New">(A_latencies(i)+1.5*EEG.srate)-1...<br>
</font></font></span>EEG=eeg_addnewevents(EEG,{[(A_latencies+1.5*EEG.srate)-1]}, {'1'});<span><br>
<br>
<font face="Courier New">%check for consistency and reorder the events chronologically...<br>
EEG=eeg_checkset(EEG,'eventconsistency');<br>
</font><br>
<div style="font-family:Tahoma;font-size:13px">
<div><font><span style="font-size:10pt">
<div>James</div>
</span></font></div>
</div>
</span></div>
<div style="font-family:'Times New Roman';color:rgb(0,0,0);font-size:16px">
<hr>
<div style="direction:ltr"><font color="#000000" face="Tahoma"><b>From:</b> <a href="mailto:eeglablist-bounces@sccn.ucsd.edu" target="_blank">eeglablist-bounces@sccn.ucsd.edu</a> [<a href="mailto:eeglablist-bounces@sccn.ucsd.edu" target="_blank">eeglablist-bounces@sccn.ucsd.edu</a>] on behalf of Makoto Miyakoshi [<a href="mailto:mmiyakoshi@ucsd.edu" target="_blank">mmiyakoshi@ucsd.edu</a>]<br>
<b>Sent:</b> February 7, 2015 1:10 AM<br>
<b>To:</b> James Desjardins<br>
<b>Cc:</b> EEGLAB List<br>
<b>Subject:</b> Re: [Eeglablist] add events to the EEG data<br>
</font><br>
</div><div><div>
<div></div>
<div>
<div dir="ltr">Dear James,
<div><br>
</div>
<div>By the way, I tried hard to come up with a trick to spare the for loop. See my code below. I mean, what is this?? But it works like a charm.</div>
<div><br>
</div>
<div>
<div>    % extract event labels and time stamps</div>
<div>    allEventLabels = mobilab.allStreams.item{eventStreanIdx}.event.label;</div>
<div>    eventTimeStamp = mobilab.allStreams.item{eventStreanIdx}.timeStamp; % in second</div>
<div><br>
</div>
<div>    % import event markers and latency to EEG.event</div>
<div>    allEventLatency = num2cell((eventTimeStamp-EEG.urxmin)*1000);</div>
<div>    allUrevent      = num2cell(1:length(allEventLatency));</div>
<div>    EEG.event = struct('type', {}, 'latency',{}, 'urevent',{});</div>
<div>    [EEG.event(1,1:length(allEventLabels)).latency] = allEventLatency{:};</div>
<div>    [EEG.event(1,1:length(allEventLabels)).type]    = allEventLabels{:};</div>
<div>    [EEG.event(1,1:length(allEventLabels)).urevent] = allUrevent{:};</div>
<div>    EEG = eeg_checkset(EEG,'eventconsistency');</div>
</div>
<div><br>
</div>
<div>This is also a convenient trick which I often use.</div>
<div><br>
</div>
<div>allEvent = {EEG.event.type}';</div>
<div>targetIdx = find(strcmp(allEvent, 'target'));</div>
<div>targetLatency = allEvent(targetIdx).latency;</div>
<div><br>
</div>
<div>Makoto</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Feb 6, 2015 at 6:19 AM, James Desjardins <span dir="ltr">
<<a href="mailto:jdesjardins@brocku.ca" target="_blank">jdesjardins@brocku.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>
<div style="direction:ltr;font-family:Tahoma;color:rgb(0,0,0);font-size:10pt">Hi Karlo,<br>
<br>
Once you load a data set, executing the following script at the command line should add the events that you are looking for...<br>
<br>
%Get the latencies (data point indices) for all 'A' type events...<br>
<font face="Courier New">A_latencies=[EEG.event(find(strcmp('A',{EEG.event.type}))).latency];<br>
<br>
%for each A_latencies add a new event type '1' with a latency of </font><font face="Courier New"><font face="Courier New">(A_latencies(i)+1.5*EEG.srate)-1...<br>
</font>for i=1:length(A_latencies);<br>
    n_events=length(EEG.event);<br>
    EEG.event(n_events+1).type='1';<br>
    EEG.event(n_events+1).latency=(A_latencies(i)+1.5*EEG.srate)-1;<br>
    EEG.event(n_events+1).urevent=n_events+1;<br>
end<br>
<br>
%check for consistency and reorder the events chronologically...<br>
EEG=eeg_checkset(EEG,'eventconsistency');<br>
</font><br>
<div><br>
<div style="font-family:Tahoma;font-size:13px">
<div><font><span style="font-size:10pt">
<div>James</div>
</span></font></div>
</div>
</div>
<div style="font-family:'Times New Roman';color:rgb(0,0,0);font-size:16px">
<hr>
<div style="direction:ltr"><font color="#000000" face="Tahoma"><b>From:</b> <a href="mailto:eeglablist-bounces@sccn.ucsd.edu" target="_blank">
eeglablist-bounces@sccn.ucsd.edu</a> [<a href="mailto:eeglablist-bounces@sccn.ucsd.edu" target="_blank">eeglablist-bounces@sccn.ucsd.edu</a>] on behalf of karlo gonzales [<a href="mailto:thats_karlo@yahoo.com" target="_blank">thats_karlo@yahoo.com</a>]<br>
<b>Sent:</b> February 5, 2015 5:16 PM<br>
<b>To:</b> EEGLAB List<br>
<b>Subject:</b> [Eeglablist] add events to the EEG data<br>
</font><br>
</div>
<div>
<div>
<div></div>
<div>
<div style="color:rgb(0,0,0);font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;font-size:16px;background-color:rgb(255,255,255)">
<div dir="ltr">Hi, </div>
<div dir="ltr"><br>
</div>
<div dir="ltr">We have an EEG data  with several events, which marked as 'A' and repeated every 5 sec. </div>
<div dir="ltr">what i am looking for is a way to add extra events to the data such as  event '1' and appears 1.5 sec after event 'A'. </div>
<div dir="ltr"><br>
</div>
<div dir="ltr">i am looking forward to hear from you.</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Thanks in advance,</div>
<div dir="ltr">Karlo</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
_______________________________________________<br>
Eeglablist page: <a href="http://sccn.ucsd.edu/eeglab/eeglabmail.html" target="_blank">
http://sccn.ucsd.edu/eeglab/eeglabmail.html</a><br>
To unsubscribe, send an empty email to <a href="mailto:eeglablist-unsubscribe@sccn.ucsd.edu" target="_blank">
eeglablist-unsubscribe@sccn.ucsd.edu</a><br>
For digest mode, send an email with the subject "set digest mime" to <a href="mailto:eeglablist-request@sccn.ucsd.edu" target="_blank">
eeglablist-request@sccn.ucsd.edu</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div>
<div dir="ltr">Makoto Miyakoshi<br>
Swartz Center for Computational Neuroscience<br>
Institute for Neural Computation, University of California San Diego<br>
</div>
</div>
</div>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">Makoto Miyakoshi<br>Swartz Center for Computational Neuroscience<br>Institute for Neural Computation, University of California San Diego<br></div></div>
</div></div>