[Eeglablist] Using the 'command' field of eeg_plot to reject trials

Matthew Moore matthew.moore at otago.ac.nz
Tue Jun 24 21:44:01 PDT 2014


Hi,

I am having a bit of trouble getting eegplot to allow inspection and editing of candidates for rejection.

I have looked at this thread: http://sccn.ucsd.edu/pipermail/eeglablist/2011/004085.html

I tried to implement the command listed there, but am having trouble. My problem may be that I can't seem to find how to load the eeglab workspace variables, other than through the gui.

I would really appreciate if someone could have a look at the code and give me some pointers.

Matt

function cleanedEEGData = detectArtefacts(eegData,locFile)
%DETECTARTEFACTS Detects artefactual data using EEGLAB's functions, then
%   displays the data in a plot for the user to check.
%   Returns the eegData with artefactual trials removed.
%   locFile is the file containing electrode locations.

    epochLength=eegData.xmax;
    epochTimeFrames=eegData.pnts;
    sampleRate=eegData.srate;
    events=eegData.event;
    nElec=eegData.nbchan;

    %Absolute limit of electrode values in uV
    lowerLimit=-150;
    upperLimit=150;

    %Maximum slope over an epoch in uV/epoch
    maxSlope=60;
    rVal=0.3;

    %Reject unlikely epochs, by number of SDs
    sdJPSingleChan=4;
    sdJPAllChans=4;

    %Reject abnormal distributions, by number of SDs
    sdKurtSingleChan=4;
    sdKurtAllChans=4;

    %Reject abnormal spectra
    thresholds=[-50 50;-100 25];
    frequencies=[0 2;20 40];

    %Do the error detecting.
    eegData=pop_eegthresh(eegData,1,1:nElec,lowerLimit,upperLimit,0,epochLength,1,0,0);
    eegData=pop_rejtrend(eegData,1,1:nElec,epochTimeFrames,maxSlope,rVal,1,0,0);
    eegData=pop_jointprob(eegData,1,1:nElec,sdJPSingleChan,sdJPAllChans,1,0);
    eegData=pop_rejkurt(eegData,1,1:nElec,sdKurtSingleChan,sdKurtAllChans,1,0);
%     eegData=pop_rejspec( eegData, 1,'elecrange',1:30,'threshold',thresholds,'freqlimits',frequencies,'eegplotcom','','eegplotplotallrej',1,'eegplotreject',0,'specdata',eegData.specdata);

    %Get the format for marking trials in an eegplot
    plotRejThr=trial2eegplot(eegData.reject.rejthresh,eegData.reject.rejthreshE,epochTimeFrames,eegData.reject.rejthreshcol);
    plotRejTre=trial2eegplot(eegData.reject.rejconst,eegData.reject.rejconstE,epochTimeFrames,eegData.reject.rejconstcol);
    plotRejJp =trial2eegplot(eegData.reject.rejjp,eegData.reject.rejjpE,epochTimeFrames,eegData.reject.rejjpcol);
    plotRejKur=trial2eegplot(eegData.reject.rejkurt,eegData.reject.rejkurtE,epochTimeFrames,eegData.reject.rejkurtcol);
%     rejSpe=trial2eegplot(eegData.reject.rejfreq,eegData.reject.rejfreqE,epochTimeFrames,eegData.reject.rejfreqcol);

    %Put the reject candidates in one array.
    rejE=[plotRejThr;plotRejTre;plotRejJp;plotRejKur];%;rejSpe];

    %command string for reject marked trials... all marked epochs...
    %from http://sccn.ucsd.edu/pipermail/eeglablist/2011/004085.html
    cmd = [ ...
    '[tmprej tmprejE] = eegplot2trial( TMPREJ,EEG.pnts,EEG.trials);' ...
    '[EEGTMP LASTCOM] = pop_rejepoch(EEG, tmprej, 1);' ...
    'if ~isempty(LASTCOM),'...
    ' [ALLEEG EEG CURRENTSET tmpcom] = pop_newset(ALLEEG, EEGTMP, CURRENTSET);' ...
    ' if ~isempty(tmpcom),' ...
    '  EEG = eegh(LASTCOM, EEG);' ...
    '  eegh(tmpcom);' ...
    '  eeglab(''redraw'');' ...
    ' end;' ...
    'end;' ...
    'clear EEGTMP tmpcom;' ...
    ] ;

    %Draw the data.
    eegplot(eegData.data,...
        'eloc_file',locFile,...
        'srate',sampleRate,...
        'events',events,...
        'winrej',rejE,...
        'command',cmd,...
        'butlabel','Reject');


end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20140625/7a898706/attachment.html>


More information about the eeglablist mailing list