[FieldTrip] How to plot ERP waveforms

"Jörn M. Horschig" jm.horschig at donders.ru.nl
Tue Jan 7 10:02:46 CET 2014


Hi,

tricky problem, and a very nasty one, but it's a simple one in the end ;)

Once you call ft_definetrial you get back a cfg with a .trl matrix. Upon 
the next call to ft_definetrial, FieldTrip checks for the presence of 
cfg.trl, and if so returns immediately (because ft_definetrial has been 
called before). Thus, in the beginning when you compute data_14, 
data_24, etc, they will all be based on the same trl. Therefore, the 
same data will be computed and all four plots will overlap.
You need to change the name of the output argument for each 
ft_definetrial call to be unique to resolve this, something like:

     
     cfg_14 = ft_definetrial(cfg);
     cfg_14.channel    = {'all'};
     data_14 = ft_preprocessing(cfg_14);
     
     cfg.trialdef.eventvalue = [24]; %markers
     cfg_24 = ft_definetrial(cfg);
     cfg_24.channel    = {'all'};
     data_24 = ft_preprocessing(cfg_24);
     


Best,
Jörn

On 1/7/2014 9:42 AM, 蔡林 wrote:
> Dear fieldtripers,
>
>      I am coming across a problem about plotting.I have four conditions in my experiment, but why did the figure have only one conditon? Please help me if you find something wrong with my codes.  My codes are as follows:
>
>
> %%preprocessing 40 subjects
> nsubjects = [1:40];
> for i=1:length (nsubjects)
>      j = nsubjects(i);
>      cfg = [];
>      cfg.dataset = sprintf('s%d-epoch-bsline.eeg', j);
>      cfg.trialdef.eventtype = 'trial';
>      cfg.trialdef.eventvalue = [14]; %markers
>      cfg = ft_definetrial(cfg);
>      cfg.channel    = {'all'};
>      data_14 = ft_preprocessing(cfg);
>      
>      cfg.trialdef.eventvalue = [24]; %markers
>      cfg = ft_definetrial(cfg);
>      cfg.channel    = {'all'};
>      data_24 = ft_preprocessing(cfg);
>      
>      cfg.trialdef.eventvalue = [34]; %markers
>      cfg = ft_definetrial(cfg);
>      cfg.channel    = {'all'};
>      data_34 = ft_preprocessing(cfg);
>      
>      cfg.trialdef.eventvalue = [44]; %markers
>      cfg = ft_definetrial(cfg);
>      cfg.channel    = {'all'};
>      data_44 = ft_preprocessing(cfg);
>
>      outfil = strcat('/EEG/data_s', sprintf('%02d', j));
>      save(outfil, 'data_14','data_24','data_34','data_44');
>      clear data_14* data_24* data_34* data_44*;
> end
> %% calculate the ERP of each subject
> nsubject = [1:40];
>
> for i=1:length (nsubject)
>      j=nsubject(1,i);
>      load (sprintf('/EEG/data_s%02d',j));
>      
>      cfg = [];
>      cfg.latency = [-0.2 1.0];
>      cfg.covariance = 'no';
>      cfg.blcovariance = 'no';
>      
>      avg_14=ft_timelockanalysis(cfg,data_14);
>      avg_24=ft_timelockanalysis(cfg,data_24);
>      avg_34=ft_timelockanalysis(cfg,data_34);
>      avg_44=ft_timelockanalysis(cfg,data_44);
>      
>      cfg = [];
>      cfg.baseline = [-0.2 0];
>      cfg.baselinetype = 'absolute';
>      base_14= ft_timelockbaseline(cfg, avg_14);
>      base_24= ft_timelockbaseline(cfg, avg_24);
>      base_34= ft_timelockbaseline(cfg, avg_34);
>      base_44= ft_timelockbaseline(cfg, avg_44);
>      
>      outfil = strcat('/EEG/baseERP_resp_s', sprintf('%02d', j));
>      save(outfil, 'base_14', 'base_24', 'base_34', 'base_44','avg_14', 'avg_24', 'avg_34','avg_44');
>      clear avg* data*;
> end
> %% calculate the grand average of the 40 subjects
> %%grand average
> cfg = [];
> nsubject = [1:40];
>
> for i=1:length (nsubject)
>      j=nsubject(1,i);
>      load(sprintf('/EEG/baseERP_resp_s%02d',j));
>      
>      sub_14(i).ERP= avg_14;
>      sub_24(i).ERP= avg_24;
>      sub_34(i).ERP= avg_34;
>      sub_44(i).ERP= avg_44;
>      clear avg*
> end
>
> grandavg_14 = ft_timelockgrandaverage(cfg, sub_14(:).ERP); %C
> grandavg_24 = ft_timelockgrandaverage(cfg, sub_24(:).ERP); %Refer
> grandavg_34 = ft_timelockgrandaverage(cfg, sub_34(:).ERP); %Semantic
> grandavg_44 = ft_timelockgrandaverage(cfg, sub_44(:).ERP); %Double
>
> outfil = strcat('/EEG/n40_grandavgERP_resp');
> save(outfil, 'grandavg_14', 'grandavg_24', 'grandavg_34', 'grandavg_44');
> %%plotting
> load /EEG/n40_grandavgERP_resp;
>
> cfg = [];
> cfg.layout = 'EEG1010.lay';
> cfg.xlim = [-0.2 1.0];
>
> cfg.baseline = 'no';
> cfg.interactive = 'no';
> cfg.showlabels = 'yes';
> cfg.colorbar = 'yes';
>
> figure;
> ft_multiplotER(cfg,grandavg_14, grandavg_24, grandavg_34, grandavg_44);
>
>
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip


-- 
Jörn M. Horschig
PhD Student
Donders Institute for Brain, Cognition and Behaviour
Centre for Cognitive Neuroimaging
Radboud University Nijmegen
Neuronal Oscillations Group
FieldTrip Development Team

P.O. Box 9101
NL-6500 HB Nijmegen
The Netherlands

Contact:
E-Mail: jm.horschig at donders.ru.nl
Tel:    +31-(0)24-36-68493
Web: http://www.ru.nl/donders

Visiting address:
Trigon, room 2.30
Kapittelweg 29
NL-6525 EN Nijmegen
The Netherlands




More information about the fieldtrip mailing list