Back to the main page.

Bug 2617 - ft_math, ft_redefinetrial, and dof

Reported 2014-06-19 15:04:00 +0200
Modified 2015-01-27 17:16:48 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to: Johanna
Depends on:
See also:

Johanna - 2014-06-19 15:04:33 +0200

Johanna - 2014-06-19 15:06:15 +0200

(oops, not sure how this bug got committed prior to me filling in any sections!)

Johanna - 2014-06-19 15:11:06 +0200

I have the problem that ft_math crashes as it tries to find a non-existent .dof field. I start with 2 tlock structures: >> tlock1 ans = avg: [62x2847 double] var: [62x2847 double] time: [1x2847 double] dof: [62x2847 double] label: {62x1 cell} dimord: 'chan_time' cfg: [1x1 struct] and tlock2 avg: [62x2800 double] var: [62x2800 double] time: [1x2800 double] dof: [62x2800 double] label: {62x1 cell} dimord: 'chan_time' cfg: [1x1 struct] I then want to shift the time axis of tlock2: cfg=[]; cfg.offset=70; tlock2_shift=ft_redefinetrial(cfg,tlock2); which now looks like: (note, no .dof field). time: [1x2847 double] label: {62x1 cell} cfg: [1x1 struct] fsample: 1000 sampleinfo: [1 2847] avg: [62x2847 double] dimord: 'chan_time' Then adding these fails in ft_math: cfg=[]; cfg.operation='add'; cfg.parameter='avg'; tlock_add=ft_math(cfg,tlock1,tlock2_shift); with this error: Reference to non-existent field 'dof'. Error in ft_selectdata>makeselection (line 424) if isnumeric(data.(datfield)) && isrow(data.(datfield)) && seldim==1 Error in ft_selectdata (line 279) if fieldhaschan, varargin{i} = makeselection(varargin{i}, find(ismember(dimtok,{'chan' '{chan}'})), selchan{i}, avgoverchan, datfield{j},; end Error in ft_math (line 129) [varargin{:}] = ft_selectdata(tmpcfg, varargin{:}); ----------------- My question is: is ft_math wrong for expecting a .dof field, or is ft_redefinetrial wrong for not retaining the .dof? Thank you, Johanna

Johanna - 2014-06-19 15:13:15 +0200

You might spot an error in my example, but that doesn't change the fundamental problem. I shifted tlock1 not tlock2.

Johanna - 2014-06-19 15:36:58 +0200

Or is it a problem in assumptions of ft_selectdata, and/or ft_datatype, and/or ft_checkdata?

Robert Oostenveld - 2014-06-19 15:43:21 +0200

dof is a rather dofficult field. It can be scalar, vector, or have the size of the data itself. In this case the problem seems to be in ft_selectdata. It basically loops over all fields, making selections along the way, but some fields are special (trialinfo, sampleinfo, cumtapcnt, and dof). I think you should be able to simplify it down to a ft_selectdata failure in a test script.

Johanna - 2014-06-19 16:14:20 +0200

I agree with the ft_selectdata. On line 142: datfield = fieldnames(varargin{1}); But if datfield does not exist in varargin{n} for n>1, then it causes the problem. I solved it in my own code by adding to around line 259 (within the for-loop over datfield): for i=1:numel(varargin) for j=1:numel(datfield) if isfield(varargin{i},datfield{j}) % new line .... end % new line end end But is that too much of a hack, and may miss things?

Robert Oostenveld - 2014-06-19 17:18:34 +0200

(In reply to Johanna from comment #6) Oh, it is due to dof being present in one, but not the other. I had missed that due to reading the comments to quickly. It should not have erred. Your solution is OK, but I would move it to the top. I.e. to add the following to line 142 for i=2:length(varargin) % only consider fields that are present in all inputs datfield = intersect(datfield, fieldnames(varargin{i})); end could you check whether this solves it? If so, I'll add it to svn (or even better: you can add it). A second solution that I in principle is also desirable is to add the dof to the output of ft_redefinetrial. But that does not fit in the code very well (due to the timelock2raw conversion), so I would not do that.

Johanna - 2014-06-19 17:56:33 +0200

I have tested your suggestion and it works, so I committed it: zumerj@psychl-132432-1:~/home/fieldtrip_svn$ svn commit utilities/ft_selectdata.m Sending utilities/ft_selectdata.m Transmitting file data . Committed revision 9640. Changing status to fixed. Thank you!