function pol = pol(x,y) %pol(x,y) for x and y column vectors r = sqrt(x.^2 + y.^2); for I = 1 : length(x), if(x(I)>0) theta(I) = atan(y(I)/x(I)); elseif(x(I)<0) if(y(I)>0) theta(I) = atan(y(I)/x(I)) + pi; elseif(y(I)<0) theta(I) = atan(y(I)/x(I)) - pi; else theta(I) = pi; end else if(y(I)>0) theta(I) = pi / 2; elseif(y(I)<0) theta(I) = -pi/2; else theta(I) = 0; end end end x=x'; y=y'; r=r'; M=[x;y;r;theta]'; label={'x','y','r','Theta'}; fprintf(' x y r Theta\n') disp(M) end