Back to the main page.

Bug 946 - ft_appenddata reportedly fails to concatenate trialinfo and sampleinfo (even when that is possible)

Reported 2011-09-10 08:35:00 +0200
Modified 2011-10-19 15:21:25 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P1 normal
Assigned to: Eelke Spaak
Depends on:
See also:

Jan-Mathijs Schoffelen - 2011-09-10 08:35:22 +0200

reported by Marianne Severens, and likely by Leo Zizlsperger: Hi Leo, Jan-Mathijs I also have the same problem. When appending data from 2 datasets the trialinfo and sampleinfo only contains info from the first dataset. And I need the information to know which trials belong to each condition. I fixed it for my data by concatenating the trialinfo and sampleinfo field myself. You just need to make sure that the funtions you use afterwards do not depend on the sampleinfo field, because this is not correct any more as Jan-Mathijs explained. I'm not sure if this is the best thing to do, but it works for me! Best, Marianne ________________________________________ From: [] On Behalf Of jan-mathijs schoffelen [] Sent: Thursday, September 08, 2011 9:19 PM To: Email discussion list for the FieldTrip project Subject: Re: [FieldTrip] ft_appenddata Hi Leo, With 'trl', are you referring to data.cfg.previous. ... .trl? I assume that data.trial (which contains the actual data) has the correct dimensionality of 1x605? In the past, fieldtrip also concatenated the trl-matrices, but we feel that this is not appropriate. The reason for this is, that the first 2 columns of these matrices represent the sample numbers that define the epochs of interest, with respect to the first sample in the recording. If the concatenated data are derived from two different datasets, these numbers become meaningless, because they cannot be interpreted unequivocally anymore. Yet, and I hope that this was motivating your question, the trl-matrix was also used (by some) to store trial-specific information, which of course still is meaningful even if the data comes from different recordings. If this indeed relates to your question, please have a look at: If your actual question is of a different nature, could you please explain a bit more what is the problem? Thanks, Jan-Mathijs On Sep 8, 2011, at 6:09 PM, Leopold Zizlsperger wrote: Hello thanks in advance for your assistance. I'd like to merge 2 datasets after preprocessing using ft_appendata. Even though it works on first view, "trl" does not add up but keeps the structure of the last dataset (304 in the example): XY_merge=ft_appenddata(cfg, x1, x2); input dataset 1, 29 channels, 301 trials input dataset 2, 29 channels, 304 trials Warning: input data comes from different datafiles In ft_appenddata at 182 concatenating the trials over all datasets removing sampleinfo field from output output dataset, 29 channels, 605 trials Do I miss the point ? Thanks Best regards Leopold I suggest to write a simple test script to validate this and fix it if necessary.

Eelke Spaak - 2011-09-26 16:37:34 +0200

Marianne, I added you to the CC list of this bug. I created a test script (test/test_bug946.m; code follows below as well), which seems to succeed for me. Could you check whether your problem persists in the latest version of Fieldtrip? (And with my test script?) I made some small changes to ft_appenddata, which are apparently unrelated to this, but might make a difference. === Test script: % make some dummy data data1 = []; data1.trial = repmat({rand(10,100)},1,10); data1.time = repmat({0.01:1},1,10); data1.label = {'CH01','CH02','CH03','CH04','CH05','CH06','CH07','CH08','CH09','CH10'}; data1.fsample = 100; data1.sampleinfo(:,1) = 1:100:901; data1.sampleinfo(:,2) = 100:100:1000; data1.trialinfo = (1:10)'; data2 = data1; data2.sampleinfo = data2.sampleinfo + 1000; data2.trialinfo = (11:20)'; % perform concatenation cfg = []; concat = ft_appenddata(cfg, data1, data2); % check whether trialinfo and sampleinfo are correct testSampleInfo = concat.sampleinfo==cat(1,data1.sampleinfo,data2.sampleinfo); testTrialInfo = concat.trialinfo==cat(1,data1.trialinfo,data2.trialinfo); wrong = []; if ~all(testSampleInfo(:)) wrong = [wrong 'sampleinfo,']; end if ~all(testTrialInfo(:)) wrong = [wrong 'trialinfo,']; end if ~isempty(wrong) error([wrong(1:end-1) ' not concatenated properly']); end