Home > bioelectromagnetism > elec_cosines.m

elec_cosines

PURPOSE ^

elec_cosines - Compute cosine of angle between electrode position vectors

SYNOPSIS ^

function [Cos] = elec_cosines(A,B)

DESCRIPTION ^

 elec_cosines - Compute cosine of angle between electrode position vectors

 Usage: [Cos] = elec_cosines(A,B)

         A,B  both Nx3 (X,Y,Z) electrode coordinates
              assuming a common origin at (0,0,0)
         COS  cosine angle between each row of A & B
              If A is Nx3 and B is Mx3, COS is NxM.

 Note:       For a complete cosine matrix, let A = B.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Cos] = elec_cosines(A,B)
0002 
0003 % elec_cosines - Compute cosine of angle between electrode position vectors
0004 %
0005 % Usage: [Cos] = elec_cosines(A,B)
0006 %
0007 %         A,B  both Nx3 (X,Y,Z) electrode coordinates
0008 %              assuming a common origin at (0,0,0)
0009 %         COS  cosine angle between each row of A & B
0010 %              If A is Nx3 and B is Mx3, COS is NxM.
0011 %
0012 % Note:       For a complete cosine matrix, let A = B.
0013 %
0014 
0015 % $Revision: 1.3 $ $Date: 2005/07/13 00:22:57 $
0016 
0017 % Licence:  GNU GPL, no implied or express warranties
0018 % History:  08/2001, Darren.Weber_at_radiology.ucsf.edu
0019 %           01/2004, Darren.Weber_at_radiology.ucsf.edu
0020 %                    cos(0) = 1, not cos(0) = 0 at line 43 ???
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

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003