Coordinates Function please I need help
2 次查看(过去 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
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!