Two output function issue
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 8 Feb. 2019
That code does not display anything. That code calculates and assigns to output variables. Anything display is outside the function.
David Goodmanson
am 8 Feb. 2019
Bearbeitet: David Goodmanson
am 8 Feb. 2019
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
am 8 Feb. 2019
Stephen23
am 8 Feb. 2019
@Patirick Legare: basic MATLAB concepts, such as how to call functions with multiple outputs, are explained in the introductory tutorials:
Highly recommended.
Antworten (0)
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!