Coordinates Function please I need help
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 20 Jul 2013
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 Comments
Image Analyst
on 20 Jul 2013
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.
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!