function [ trials ] = trial_definition_ft( file_list, marker_name, prestim, postim, emg_names ) %trial_definition_ft Define trials % Detailed explanation goes here trials = [] ; for file_id = 1:length(file_list) cfg=[]; cfg.dataset = file_list{file_id}; cfg.trialdef.eventtype = marker_name ; cfg.trialfun = 'mrkfiftrialsel'; cfg.trialdef.poststim = postim ; cfg.trialdef.eventvalue = 0 ; cfg.trialdef.prestim = prestim ; cfg.channel = {'MEG'}; cfg = ft_definetrial(cfg); trials_tmp=ft_preprocessing(cfg); if ~isempty(emg_names) %% Preprocess emg tmp_meg_data = trials_tmp ; trials_tmp = [] ; cfg = []; cfg.dataset = tmp_meg_data.cfg.dataset; cfg.trl = tmp_meg_data.cfg.trl; cfg.continuous = 'yes'; cfg.demean = 'yes'; cfg.dftfilter = 'yes'; cfg.channel = emg_names; cfg.hpfilter = 'yes'; cfg.hpfreq = 10; cfg.rectify = 'yes'; emg = ft_preprocessing(cfg); trials_tmp = ft_appenddata([], tmp_meg_data, emg); end if file_id > 1 trials = ft_appenddata([], trials, trials_tmp); else trials=trials_tmp; grad_tmp=trials.grad; end end if file_id > 1 trials.grad = grad_tmp ; end end