0001 function [Cos] = elec_cosines(A,B)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 eegversion = '$Revision: 1.3 $';
0024 fprintf('ELEC_COSINES [v %s]\n',eegversion(11:15));
0025
0026 if isempty(A), error('Input matrix A is empty\n'); end
0027 if isempty(B), error('Input matrix B is empty\n'); end
0028
0029 As = size(A);
0030 if ~isequal(As(2),3),
0031 if isequal(As(1),3), A = A';
0032 else error('Input matrix A should be Nx3 [x y z] coordinates\n');
0033 end
0034 end
0035 Bs = size(B);
0036 if ~isequal(Bs(2),3),
0037 if isequal(Bs(1),3), B = B';
0038 else error('Input matrix B should be Nx3 [x y z] coordinates\n');
0039 end
0040 end
0041
0042 fprintf('...calculating cosines\n'); tic
0043
0044 for a = 1:size(A,1), Aa = A(a,:); A_len = norm(Aa);
0045 for b = 1:size(B,1), Bb = B(b,:); B_len = norm(Bb);
0046
0047 Cos(a,b) = dot(Aa,Bb) / (A_len * B_len);
0048 end
0049 end
0050
0051 t=toc; fprintf('...done (%6.2f sec)\n\n',t);
0052
0053 return