[FieldTrip] Can I define the trials with only header, data, and event (Schoffelen, J.M. (Jan Mathijs))

Shikai Chen 3190101881 at zju.edu.cn
Thu May 29 16:20:22 CEST 2025


Hi Jan-Mathijs,

Thank you so much for your reply! I want to define the trials, but I found in the tutorials, I have to use the name of the MEG data, like cfg.dataset = ‘filename”. And my two data files are continuous—the second starts in the middle of one trial from the first one. So I want to combine them into one, save the data as new file and then define the trials. I was wondering if I have to use cfg.dataset = ‘filename”.

I also tried ft_appenddata. But I am confused what should I do after this to define the trials. When I had the defined trials in cfg, and tried this: data = ft_preprocessing(cfg,data), it shows warning: The field cfg.trl is forbidden, it will be removed from your configuration. So I can’t successfully define the trials through this.

Thank you again for your help!

Best,
Shikai

> 2025年5月29日 18:00,fieldtrip-request at science.ru.nl 写道:
> 
> Hi Shikai,
> 
> Please can you reformulate your question a bit more coherently (provided the below does not give you enough pointers to proceed with your endeavours)? You mention a lot of functions and a lot of things, but it is unclear what you really aim to achieve. It’s unclear why you think that you need to use ft_write_data to ’stitch’ two raw datafiles together in a ‘raw’ fileformat that is the same (or similar) as the vendor specific acquisition system.
> 
> If you are facing the reality that the data recorded from a single subject ended up in 2 datafiles, and need to be processed together at some point, then import/epoch the data per file, and append the two resulting data structures in FieldTrip, using ft_appenddata.
> 
> Good luck,
> Jan-Mathijs
> 
> May I ask if I can define the trials with only header, data, and event? I see cfg.dataset = “filename” and can I use the information of header, data, and event instead? These are generated by ft_read_header, ft_read_data and ft_read_event.
> 
> My MEG data is recorded into two data sets accidentally. So I combine these two into one using ft_read_header, ft_read_data and ft_read_event and cat. But I didn’t find the “MEG "format in ft_write_data and other formats would lose some information and regard the data as EEG data. So how can I make some changes to the following code?
> hdr1 = ft_read_header(filename1);
> dat1 = ft_read_data(filename1);
> evt1 = ft_read_event(filename1);
> hdr2 = ft_read_header(filename2);
> dat2 = ft_read_data(filename2);
> evt2 = ft_read_event(filename2);
> hdr = hdr1;
> hdr.nSamples = hdr1.nSamples + hdr2.nSamples;
> dat = cat(2,dat1,dat2);
> nsamples1 = hdr1.nSamples;
> for i = 1:length(evt2)
> evt2(i).sample = evt2(i).sample + nsamples1;
> end
> evt = cat(1,evt1,evt2);
> 
> cfg = [];
> cfg.dataset = [path, '\data.vhdr’];
> cfg.trialfun = 'trialfun_conditionaltrigger’;
> cfg.trialdef.pre = 5;
> cfg.trialdef.post = 68;
> cfg = ft_definetrial(cfg);
> data = ft_preprocessing(cfg);
> Thank you so much for your help!
> 
> Best,
> Shikai

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20250529/429c64f9/attachment.htm>


More information about the fieldtrip mailing list