-
Notifications
You must be signed in to change notification settings - Fork 7
/
fixdipole.m
52 lines (46 loc) · 1.74 KB
/
fixdipole.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function dip = fixdipole(dip)
% FIXDIPOLE ensures that the dipole position and moment are
% consistently represented throughout FieldTrip functions.
% Copyright (C) 2009, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id: fixdipole.m 946 2010-04-21 17:51:16Z roboos $
[m, n] = size(dip.pos);
if n==3
% the input representation is Nx3, which is what we want
elseif m==3
% it is possible to translate it into a Nx3 unambiguously
warning('input dipole positions should be specified as Nx3 matrix');
dip.pos = dip.pos';
elseif m==1
% it is possible to translate it into a Nx3 unambiguously
warning('input dipole positions should be specified as Nx3 matrix');
dip.pos = reshape(dip.pos, 3, n/3)';
else
% it is not clear how to convert to a Nx3 matrix
error('input dipole positions should be specified as Nx3 matrix');
end
if isfield(dip, 'mom')
ndip = size(dip.pos,1);
if numel(dip.mom)==ndip*3
ntime = 1;
else
ntime = numel(dip.mom)/(ndip*3);
end
dip.mom = reshape(dip.mom, ndip*3, ntime);
end