[FieldTrip] multiple subject code

mubeen afzal mubafzal at hotmail.com
Sun Feb 27 21:17:29 CET 2022

Hi I have a silly question,

How does one use a folder of edf files of subjects to repeat the code below so that I can perform a grand average in the end? Or does each file have to be run seperately with seperate codes?


cfg            = [];
cfg.dataset    = 'C:\Users\mubaf\OneDrive\Desktop\MY BRAINSTORM\Cases GGE\JJ_05-01-2017.edf';
cfg.channel    = {'EEG Fp1' 'EEG Fp2' 'EEG F7' 'EEG F3' 'EEG Fz' 'EEG F4'...
    'EEG F8' 'EEG T7' 'EEG C3' 'EEG Cz' 'EEG T8' 'EEG P7' 'EEG P3' 'EEG C4'...
    'EEG Pz' 'EEG P4' 'EEG O1' 'EEG O2', 'EEG T3', 'EEG T5', ...
    'EEG T4', 'EEG T6' 'Fp1' 'Fp2' 'F7' 'F3' 'Fz' 'F4' 'F8' 'T7' 'C3'...
    'Cz' 'C4' 'T8' 'P7' 'P3' 'Pz' 'P4' 'O1' 'O2', 'T3', 'T5', 'T4', 'T6'};%'P8'
hdr = ft_read_header(cfg.dataset);
event = ft_read_event(cfg.dataset, 'detectflank', []);

cfg.trialdef.prestim   = 0.5;                   % in seconds
cfg.trialdef.poststim  = 2.5;     % in seconds
cfg.trialdef.eventtype = 'annotation'
cfg.trialdef.eventvalue = 'Ep.sw';
cfg = ft_definetrial(cfg);

datatrials  = ft_preprocessing(cfg);
cfg.continuous              = 'no'
cfg.blocksize  = 10
cfg.channel = 'eeg'
cfg = ft_databrowser(cfg, datatrials)

%power analysis (calls 1 function)
cfg.method = 'mtmfft'
cfg.output ='pow'
cfg.channel  = 'all';
cfg.trials = 'all'
cfg.keeptrials = 'yes' %all trials powerspectrum available if yes in freq.powspctrm
cfg.keeptapers = 'no'
cfg.pad = 'maxperlen'
cfg.polyremoval = 0 %(0 demeans only/1 demeans and detrends/-1 no removal)
cfg.taper = 'hann'
cfg.foilim = [2 50]
freq = ft_freqanalysis(cfg, datatrials);

cfg.variance      = 'yes'
cfg.jackknife     = 'no'
cfg.keeptrials    = 'yes'
cfg.channel       = 'all'
cfg.trials        = 'all'
cfg.frequency     = [2 50]
cfg.latency       = 'all'
[descrip] = ft_freqdescriptives(cfg, freq)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20220227/99ab992b/attachment.htm>

More information about the fieldtrip mailing list