function [beta,LengthV] = angCEA_2D(x,y)
% funkce pro výpočet uhlu elektrické ose srdce
r=sqrt(x.^2+y.^2); [LengthV,l] = max(r);

% for j=1:length(l)
%     Y(j)=y(l(j),j);
%     X(j)=x(l(j),j);
% end

X=x(l); Y=y(l);

 for i=1:length(X)                        
        if (Y(i)>0)&&(X(i)>0) 
            beta(i) = atand(X(i)./Y(i));            
        elseif (Y(i)<0)&&(X(i)>0)
            beta(i) = atand(abs(Y(i))./X(i))+90;           
        elseif (Y(i)<0)&&(X(i)<0)
            beta(i) = 270-atand(Y(i)./X(i));            
        elseif (Y(i)>0)&&(X(i)<0)
            beta(i) = 360-atand(abs(X(i))./Y(i));
        elseif (Y(i)==0)&&(X(i)>0)
            beta(i) = 90;
        elseif (Y(i)==0)&&(X(i)<0)
            beta(i) = 270;
        elseif (Y(i)>0)&&(X(i)==0)
            beta(i) = 0; % 360
        elseif (Y(i)<0)&&(X(i)==0)
            beta(i) = 180;
        end       
 end