function theta = vectorAngles(vect1, vect2, dim)
%% theta] = vectorAngles(vect1, vect2, dim)
%
% Angle (rad) between vector vect1 and vect2. dim parameter is used if several
% vectors are stored in a matrix (see sqrt help for exemple) 
%
%
% $Revision: 11 $
% $Author: lenertz $
% $Date: 2015-07-10 14:32:19 +0200 (ven., 10 juil. 2015) $

if nargin < 3;
    dim = ndims(vect1);
end


vect1_norm = sqrt(sum(vect1.^2,dim));
vect2_norm = sqrt(sum(vect2.^2,dim)); 

% len = size(vect1);
% if dim == 2 && len(1) == 1;
%     dim = 1;
% end        

theta = acos(dot(vect1,vect2,dim)./(vect1_norm.* vect2_norm));
end