File size: 2,155 Bytes
03a0748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function [distmatrixpol distmatrixxyz distmatrixproj] = distancematrix(EEG,eeg_chans)

% Copyright (C) 2010 Hugh Nolan, Robert Whelan and Richard Reilly, Trinity College Dublin,
% Ireland
% nolanhu@tcd.ie, robert.whelan@tcd.ie
%
% This program 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 2 of the License, or
% (at your option) any later version.
%
% This program 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 this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

num_chans = size(EEG.data,1);
distmatrix = zeros(length(eeg_chans),length(eeg_chans));
distmatrixpol = [];
for chan2tst = eeg_chans;
	for q=eeg_chans
		distmatrixpol(chan2tst,q)=sqrt(((EEG.chanlocs(chan2tst).radius^2)+(EEG.chanlocs(q).radius^2))-(2*((EEG.chanlocs(chan2tst).radius)*...
			(EEG.chanlocs(q).radius)*cosd(EEG.chanlocs(chan2tst).theta - EEG.chanlocs(q).theta))));%calculates the distance between electrodes using polar format
	end
end

locs = EEG.chanlocs;
for u = eeg_chans
	if ~isempty(locs(u).X)
		Xs(u) = locs(u).X;
	else
		Xs(u) = 0;
	end
	if ~isempty(locs(u).Y)
		Ys(u) = locs(u).Y;
	else
		Ys(u) = 0;
		end
	if ~isempty(locs(u).Z)
		Zs(u) = locs(u).Z;
	else
		Zs(u) = 0;
	end
end
Xs = round2(Xs,6);
Ys = round2(Ys,6);
Zs = round2(Zs,6);

for u = eeg_chans
	for v=eeg_chans
		distmatrixxyz(u,v) = dist(Xs(u),Xs(v))+dist(Ys(u),Ys(v))+dist(Zs(u),Zs(v));
	end
end
D = max(max(distmatrixxyz));
distmatrixproj = (pi-2*(acos(distmatrixxyz./D))).*(D./2);
	function d = dist(in1,in2)
		d = sqrt(abs(in1.^2 - in2.^2));
	end

	function num = round2(num,decimal)
		num = num .* 10^decimal;
		num = round(num);
		num = num ./ 10^decimal;
	end
end