Code covered by the BSD License

# VECT_DIR

by

Function to calculate the angular difference, circular mean and variance.

vect_dir(a, b)
```%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INPUT: two matching nx2 or nx3 arrays a and b representing 2D/3D        %
% directional vectors e.g. for the 3D case a = [1 1 1; 1 1 1; 1 1 1],     %
% b = [2 2 2; 2 2 2; 2 2 2] or two matching nx4 / nx6 arrays representing %
% 2D/3D lines                                                             %
%                                                                         %
% OUTPUT: Single column vector RADS containing the angle in radians       %
%         between a and b                                                 %
%         Single variable ARC_MEAN containing the circular mean mean      %
%                                                                         %
% USAGE: [rads arc_mean arc_vars] = vect_dir(a, b)                        %
%                                                                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [rads arc_mean arc_vars] = vect_dir(a, b)

%Error check
[ra ca] = size(a);
[rb cb] = size(b);
if(ra~=rb)
error('Point arrays must be of equal size');
end

if(ca~=6 || cb~=6)
else if (ca~=4 || cb~=4)
else if (ca~=3 || cb~=3)
else if (ca~=2 || cb~=2)
error('Must be end node coordinates of 2D/3D lines or 2D/3D directional vectors');
end
end
end
end

%The 3D line case
if ca ==6
%Calculate direction vectors
%Preallocate
bdir = zeros(size(b,3));

%Difference
bdir(:,1)=b(:,1)-b(:,3); bdir(:,2)=b(:,2)-b(:,4);bdir(:,3)=b(:,3)-b(:,6);

%Calculate 3D angle between two 3D vectors
for i=1:size(a,1)
end

%The 3D directional vector case
else if ca==3
for i=1:size(a,1)
end

%The 2D line case
else if ca==4

%Calculate direction vectors
%Preallocate
bdir = zeros(size(b,2));

%difference
bdir(:,1)=b(:,1)-b(:,3); bdir(:,2)=b(:,2)-b(:,4);

%Calculate 3D angle between two 2D vectors
for i=1:size(a,1)
end

%The 2D directional vector case
else if ca==4
for i=1:size(a,1)
end
end
end
end
end

% Compute circular mean