elec_cosines.m

来自「Matlab下的EEG处理程序库」· M 代码 · 共 45 行

M
45
字号
function [Cos] = elec_cosines(A,B)
% ELEC_COSINES - Compute cosine of angle between electrode position vectors
%
% Useage: [Cos] = elec_cosines(A,B)
%
%         A,B  both Nx3 (X,Y,Z) electrode coordinates
%         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.
%

% $Revision: 1.2 $ $Date: 2003/03/02 03:20:44 $

% Licence:  GNU GPL, no implied or express warranties
% History:  08/01, Darren.Weber@flinders.edu.au
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isempty(A), error('Input matrix A is empty\n'); end
if isempty(B), error('Input matrix B is empty\n'); end

As = size(A);
if ~isequal(As(2),3),
    if isequal(As(1),3), A = A.';
    else error('Input matrix A should be Nx3 [x y z] coordinates\n');
    end
end
Bs = size(B);
if ~isequal(Bs(2),3),
    if isequal(Bs(1),3), B = B.';
    else error('Input matrix B should be Nx3 [x y z] coordinates\n');
    end
end

for     a = 1:size(A,1),  Aa = A(a,:); A_len = sqrt( sum(Aa.^2));
    for b = 1:size(B,1),  Bb = B(b,:); B_len = sqrt( sum(Bb.^2));
        
        if( Aa == Bb ), Cos(a,b) = 0;
        else            Cos(a,b) = dot(Aa,Bb) / (A_len * B_len);
        end
    end
end

return

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?