Coordinates Function please I need help

1 次查看(过去 30 天)
I am working on this function where I have to give the coordinates of a specific point in the 4 quadrants in radians and degrees , I have been working on it and still have not been able to figure it out please I need some help.
if true
function [th rad]=cartopolar25(x,y)
th=atan(y/x);
rad=sqrt(x^2+y^2);
if x>0
return
y>0
th=th;
else
if x>0
return
y<0
th=-th;
else
if x<0
return
y>0
th=180+th;
else
th=-180+th;
end
end
end
% code
end

回答(1 个)

Image Analyst
Image Analyst 2013-7-20
That is not proper syntax. First of all, if x > 0 you return so it never ever gets a chance to do the y>0 line (which is useless anyway), or the equally useless th=th line. Why not just make it simple and have 4 cases for the 4 quadrants:
if x>0 && y>0
% Code
elseif x>0 && y<0
% Code
elseif x<0 && y>0
% Code
elseif x<0 && y<0
% Code
end
  2 个评论
jessica
jessica 2013-7-20
ok thats way better , but you mean in the code to add th and rad, can you please give me an example just of the first quadrant so I can do the others, thank you for your time and help, I greatly aprreciated
Image Analyst
Image Analyst 2013-7-20
I think you can do it if you think hard enough about it. Just change the sign of th and add or subtract an angle as necessary to get the right value for the quadrant. I think you can do it even if I don't do the first one for you because you're a smart engineer and this is just 10th grade trigonometry.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by