Coordinates Function please I need help

조회 수: 5 (최근 30일)
jessica
jessica 2013년 7월 20일
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에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by