Skip to content

Commit 175e3a8

Browse files
support the specification of a combined EEG and MEG volume conduction model as a cell array
See also http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3089 and http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=2684
1 parent daa8e1c commit 175e3a8

File tree

8 files changed

+265
-111
lines changed

8 files changed

+265
-111
lines changed

fileio/private/ft_datatype_headmodel.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@
9696
return;
9797
end
9898

99+
if iscell(headmodel)
100+
% this might represent combined EEG, ECoG and/or MEG
101+
for i=1:numel(headmodel)
102+
% call recursively
103+
headmodel{i} = ft_datatype_headmodel(headmodel{i}, varargin{:});
104+
end
105+
return
106+
end
107+
99108
switch version
100109

101110
case '2015'

forward/ft_convert_units.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
% are specified, this function will only determine the native geometrical
2020
% units of the object.
2121
%
22-
% See FT_ESTIMATE_UNITS, FT_READ_VOL, FT_READ_SENS
22+
% See also FT_ESTIMATE_UNITS, FT_READ_VOL, FT_READ_SENS
2323

24-
% Copyright (C) 2005-2013, Robert Oostenveld
24+
% Copyright (C) 2005-2016, Robert Oostenveld
2525
%
2626
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
2727
% for the documentation and details.
@@ -59,6 +59,13 @@
5959
end
6060
obj = tmp;
6161
return
62+
elseif iscell(obj) && numel(obj)>1
63+
% deal with a cell array
64+
% this might represent combined EEG, ECoG and/or MEG
65+
for i=1:numel(obj)
66+
obj{i} = ft_convert_units(obj{i}, target, varargin{:});
67+
end
68+
return
6269
end
6370

6471
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

forward/ft_prepare_vol_sens.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
%
5959
% $Id$
6060

61+
if iscell(headmodel) && iscell(sens)
62+
% this represents combined EEG, ECoG and/or MEG
63+
for i=1:numel(headmodel)
64+
[headmodel{i}, sens{i}] = ft_prepare_vol_sens(headmodel{i}, sens{i}, varargin{:});
65+
end
66+
return
67+
end
68+
6169
% get the optional input arguments
6270
% fileformat = ft_getopt(varargin, 'fileformat');
6371
channel = ft_getopt(varargin, 'channel', sens.label); % cell-array with channel labels, default is all
@@ -357,9 +365,9 @@
357365

358366
case {'slab_monopole'}
359367
% electrodes' all-to-all distances
360-
numel = size(sens.elecpos,1);
361-
ref_el = sens.elecpos(1,:);
362-
md = dist( (sens.elecpos-repmat(ref_el,[numel 1]))' );
368+
numelc = size(sens.elecpos,1);
369+
ref_elc = sens.elecpos(1,:);
370+
md = dist( (sens.elecpos-repmat(ref_elc,[numelc 1]))' );
363371
% choose min distance between electrodes
364372
md = min(md(1,2:end));
365373
pos = sens.elecpos;

forward/private/ft_datatype_headmodel.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@
9696
return;
9797
end
9898

99+
if iscell(headmodel)
100+
% this might represent combined EEG, ECoG and/or MEG
101+
for i=1:numel(headmodel)
102+
% call recursively
103+
headmodel{i} = ft_datatype_headmodel(headmodel{i}, varargin{:});
104+
end
105+
return
106+
end
107+
99108
switch version
100109

101110
case '2015'

private/ft_fetch_vol.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
%
1111
% See also FT_READ_VOL, FT_FETCH_DATA
1212

13-
% Copyright (C) 2011, Jörn M. Horschig
13+
% Copyright (C) 2011, J?rn M. Horschig
1414
%
1515
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
1616
% for the documentation and details.
@@ -41,6 +41,9 @@
4141
headmodel = ft_read_vol(cfg.headmodel);
4242
elseif isfield(cfg, 'headmodel') && (isstruct(cfg.headmodel) || isa(cfg.headmodel, 'config'))
4343
headmodel = cfg.headmodel;
44+
elseif isfield(cfg, 'headmodel') && iscell(cfg.headmodel)
45+
% this might represent combined EEG, ECoG and/or MEG
46+
headmodel = cfg.headmodel;
4447
else
4548
error('no headmodel specified');
4649
end

private/prepare_headmodel.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,20 @@
8787
end
8888

8989
% ensure that these are a struct, which may be required in case configuration tracking is used
90-
headmodel = struct(headmodel);
91-
sens = struct(sens);
90+
% FIXME this fails for combined EEG+MEG
91+
% headmodel = struct(headmodel);
92+
% sens = struct(sens);
9293

9394
% the prepare_vol_sens function from the forwinv module does most of the actual work
9495
[headmodel, sens] = ft_prepare_vol_sens(headmodel, sens, 'channel', cfg.channel, 'order', cfg.order);
9596

9697
% update the selected channels in the configuration
97-
cfg.channel = sens.label;
98+
if iscell(sens)
99+
% this represents combined EEG, ECoG and/or MEG
100+
cfg.channel = {};
101+
for i=1:numel(sens)
102+
cfg.channel = cat(1, cfg.channel, sens{i}.label(:));
103+
end
104+
else
105+
cfg.channel = sens.label;
106+
end

0 commit comments

Comments
 (0)