% Define trialscfg=[];cfg.dataset=%cfg.trialdef.prestim=%cfg.trialdef.poststim=%cfg.trialdef.eventvalue=%cfg.trialfun=%cfg=ft_definetrial(cfg);%Remove trials from cfg.trl that have negative sample index for trial startnotneg=cfg.trl(:,1)>=0cfg.trl=cfg.trl(notneg,:)%Remove trials from cfg.trl that have higher sample index than exist in filetoolate=cfg.trl(:,2)<max([cfg.event.sample]);cfg.trl=cfg.trl(toolate,:)% Preprocesscfg.channel=%data=ft_preprocessing(cfg);