function [sco] = cart2sphm(X)
% [ sco ] = cart2sphm( X )
% Transforms cartesian to hypershperical coordinates
%
% Input:
%   X       cartesian coordinates
%
% Output:
%   sco     angles of spherical coordinates, last entry: radius
%
% Note: This function behaves different then matlabs cart2sph, but the same as matlabs cart2pol
%
% E.g.: cart2sphm([2 3 1])
%
%
% See also: sph2cartm2, cart2sphm, sph2cartm, cart2sphm2
%
% Written by: tommsch, 2018

if(nargin==0 || isempty(X)); sco=[]; return; end;

dim=length(X);
sco=zeros(1,dim);

for i=1:dim-1
    sco(i)=acos(X(i)/norm(X(i:end)));
end
if(X(end)<0); sco(dim-1)=-sco(dim-1); end;
sco(dim)=norm(X);

end

function dummy; end %#ok<DEFNU> %Generates an error, if the 'end' of a function is missing.   