This function is supposed to display the radius and the angle when you input the coordinates and it's only displaying the radius can someone help me out ?
Thanks in advance
function[r,d]=Cartapol(x,y)
r=sqrt((x^2)+(y^2));
d=atand(y/x);
if(x<0)
d=180+d;
elseif (x>0 && y<0)
d=360+d;
elseif x==0 && y==0
d=0;
elseif x==0 && y<0
d=270;
end

댓글 수: 4

Walter Roberson
Walter Roberson 2019년 2월 8일
That code does not display anything. That code calculates and assigns to output variables. Anything display is outside the function.
David Goodmanson
David Goodmanson 2019년 2월 8일
편집: David Goodmanson 2019년 2월 8일
Hi Patirick,
are you asking for both outputs? [r d] = Cartapol(1,2) works just fine.
Incidentally, it's good to know what happens with atan in all four quadrants, but you can save yourself some coding by using atan2d(y,x).
Patirick Legare
Patirick Legare 2019년 2월 8일
Hi David ,
Thank you for that shortcut I will definetly be using this.Turns out that the fuction did work just fine I was not calling it properly... I am very new to this so it's a process.
Thanks for you help I really appreciate it !
Stephen23
Stephen23 2019년 2월 8일
@Patirick Legare: basic MATLAB concepts, such as how to call functions with multiple outputs, are explained in the introductory tutorials:
Highly recommended.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2019년 2월 8일

댓글:

2019년 2월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by