Print

Print


Dear Muhammad,

The code I provide works with D as an object. So if you start with

D = spm_eeg_load('filename');

it should work. The code you wrote uses the internal struct. This is
something I'm trying to discourage and in any case don't provide support for
since this kind of code is not guaranteed to work with further development
of SPM and can generate inconsistencies in the data structure in ways that
the object code doesn't always detect.

Best,

Vladimir

Sent from my iPad

On 24 Aug 2010, at 23:06, MP <[log in to unmask]> wrote:

Hi Vladimir,

Thanks for the reply. I do see the logic you are trying to apply to reject
these trials. However, I am having difficulty using the reject command. When
I type in


for i = 1:length(D.trials)
ev = D.trials(1,i).events;
if numel(ev)>1
D = reject(D,i,1);
end
end

It gives me the following error

??? Undefined function or method 'reject' for input arguments of type
'struct'.

What can I do to avoid this error?

Many thanks,

- Muhammad


On Tue, Aug 24, 2010 at 4:21 PM, Vladimir Litvak
<[log in to unmask]>wrote:

> Dear Muhammad,
>
> I understand your problem better now. The thing is that 'Multiple events'
> is just something that the reviewing tool shows when there are more than one
> triggers in a trial which happens in your case because there are many
> triggers recorded at the same time point. But this doesn't mean that the
> type and value of those triggers are really different from the normal ones.
> in fact they are not, that's why you get those garbage trials.
>
> So you need to use some other criterion to get rid of those trials. I'm
> away from my desk right now so I can't write a working piece of code for you
> and test it, but one idea is to use the fact that only the faulty trials
> have multiple triggers and do something like:
>
> for i = 1:D.ntrials
>   ev=D.events(i);
>   if numel(ev{1})>1
>     D = reject(D, i, 1);
>   end
> end
>
> save(D);
>
> and then use 'Remove bad trials' to physically remove the bad trials from
> the file. An alternative way would be not to generate those trials in the
> first place. That can be done for instance by editing the events list in the
> continuous file and deleting those events based on their timing or by using
> spm_eeg_definetrial to generate the trl matrix based on the triggers and
> then remove some rows from this matrix before passing it to the epoching
> function. But I hope one way will be enough for you.
>
> Best,
>
> Vladimir
>
> Sent from my iPad
>
> On 24 Aug 2010, at 14:52, MP <[log in to unmask]> wrote:
>
> hi Vladimir,
>
> Actually, in our EEG hardware setup we have a switch that needs to be
> flipped when we run our studies. This switch-flipping produces a burst of
> garbage triggers (all at the same time, and the whole clump can be seen on
> the acquisition screen) at the start of the acquisition but varies in the
> number (20 - 80 triggers), but the value of these triggers are same as our
> trigger of interest. I am using the following code in my script to epoch the
> data:
>
> S = [];
> S.D = fullname3;
> S.fsample = 500;
> S.timeonset = 0;
> S.bc = 1;
> S.inputformat = [];
> S.pretrig = -498;
> S.posttrig = 2000;
> S.trialdef(1).conditionlabel = 'Stim1';
> S.trialdef(1).eventtype = 'trigger';
> S.trialdef(1).eventvalue = 1;
> S.trialdef(2).conditionlabel = 'Stim2';
> S.trialdef(2).eventtype = 'trigger';
> S.trialdef(2).eventvalue = 2;
> S.trialdef(3).conditionlabel = 'Stim3';
> S.trialdef(3).eventtype = 'trigger';
> S.trialdef(3).eventvalue = 3;
> S.trialdef(4).conditionlabel = 'Stim4';
> S.trialdef(4).eventtype = 'trigger';
> S.trialdef(4).eventvalue = 4;
> S.reviewtrials = 0;
> S.save = 0;
> S.epochinfo.padding = 0;
> D = spm_eeg_epochs(S);
>
>
> So, ideally, only these four events should be epoched. However, the
> 'garbage-triggers' also show up in the epoched file with the type, value,
> duration and time fields saying as 'multiple events', while these are
> labelled as our trigger of interest. Now, I would like to know how I can
> discard these trials from the epoched file.
>
> Thanks
>
> - Muhammad
>
>
>
> On Thu, Aug 19, 2010 at 12:38 PM, Vladimir Litvak <<[log in to unmask]>
> [log in to unmask]> wrote:
>
>> Hi Muhammad,
>>
>> I'm afraid I still don't completely understand the problem. When you
>> epoch the data you are presented with a list of triggers including
>> type and value and you need to select some of those triggers to define
>> epochs around. So if you just don't select the trigger you don't want,
>> wouldn't it solve the problem?
>>
>> Vladimir
>>
>> On Thu, Aug 19, 2010 at 4:25 PM, MP < <[log in to unmask]>
>> [log in to unmask]> wrote:
>> > Hello Vladimir,
>> > Thanks for your response. i was indeed meant "events" when I said trials
>> > (sorry for the confusion). Actually our system sometimes produces
>> triggers
>> > that we are not interested in, but have the same number as the trigger
>> of
>> > interest. Luckily, SPM detects them with a different "type" and "value".
>> So,
>> > I wanted to include some code in the script that marks these events as
>> bad
>> > before they are averaged in with the triggers of interest.
>> > i will really if you could direct me to the right way of doing it.
>> > Thanks
>> > - Muhammad
>> >
>> >
>> > On Thu, Aug 19, 2010 at 6:15 AM, Vladimir Litvak <<[log in to unmask]>
>> [log in to unmask]>
>> > wrote:
>> >>
>> >> Dear Muhammad,
>> >>
>> >> On Thu, Aug 19, 2010 at 12:20 AM, MP < <[log in to unmask]>
>> [log in to unmask]> wrote:
>> >> > Hello SPMers,
>> >> > i am doing EEG (NeuroScan SynAmp2) analysis using SPM8 and I have a
>> >> > couple
>> >> > of very basic questions:
>> >> > 1. In order to do re-referencing to mastoids, can I just add the
>> >> > following
>> >> > to my pre-processing script?
>> >> > S = [];
>> >> > S.D = filename;
>> >> > S.refchan = {
>> >> >              'M1'
>> >> >              'M2'
>> >> >              };
>> >> > D = spm_eeg_reref_eeg(S);
>> >>
>> >> Yes.
>> >>
>> >> > 2. There are some trials with a specific "type and "value", which i
>> >> > would
>> >> > like to delete before averaging my data. Is it possible through a
>> script
>> >> > and
>> >> > without manually deleting them from each file?
>> >>
>> >> Type and value are properties of events (a.k.a. triggers) and not of
>> >> trials. Trials are characterized by condition labels that you assign
>> >> when epoching. If the trials you want to remove have condition label
>> >> different from others then you shouldn't worry because when you
>> >> average they will be averaged separately and won't affect the other
>> >> trials. You can then remove their average if you want by marking it as
>> >> bad and using Other/'Remove bad trials'. If those trials have the same
>> >> condition label as other trials there might still be a way to identify
>> >> them based on events stored with each trial. That'll work unless you
>> >> merged datasets at some point. If that's what you want to do, let me
>> >> know and I'll send you some example code, but wouldn't it be simpler
>> >> to avoid creating these trials in the first place? In any case you can
>> >> mark trials as bad in script using something like:
>> >>
>> >> D = spm_eeg_load;
>> >> D = reject(D, [1 2 3 4], 1);
>> >> save(D);
>> >>
>> >> Vladimir
>> >
>> >
>>
>
>