MATLAB: A function to draw a circle with only radius as parameter

functionMATLABread the faq

Hello I need help to create a function that will help me draw a circle with a given radius.
So the function can only have the radius as parameter.
For example if I type draw_circle(5) I want to have a plot of a circle with radius 5. Since the equation is y^2+x^2=r^2 —> y=+/-sqrt(r^2-x^2) it feels like I need two parameters in the function one for x and one for r.
So basically can someone help me construct a function draw_circle(r) that plots a circle with radius 5.
Thanks!

Best Answer

function cercle(r)
x=-r:.01:r
y=sqrt(r^2-x.^2)
hold on;
plot(x,y);
plot(x,-y)
call the function
cercle(5)