MATLAB: Please help with this function

matlab function

function [th rad]=cartopolar25(x,y
t=atan(y/x); rad=sqrt(x^2+y^2); if if x<0 if y<0 th=180+t return else th=180-t return end else if y<0 th=-t return else th=t return end end
end end
Hi I need help with this code, if you guys see any mistakes please let me know. I have to make a function to determine the polar coordinates from the Cartesian plane, thanks for the help yes I was able to get the degrees now all I need is the radians any tips with this current format thanks

Best Answer

your function is this:
function [th rad]=cartopolar25(x,y)
th = atan(y/x);
rad = sqrt(x^2+y^2);
if x<0
if y<0
th=th+180;
else
th=th-180;
end
else
if y<0
th=-th;
end
end
and you need to call it like this:
[t,r] = cartopolar25(-11,20);
the output will be:
t =
-181.0680
r =
22.8254