Home > OS >  How to turn this MATLAB script into a function?
How to turn this MATLAB script into a function?

Time:09-01

this code is basically how to graph a circle with a radius of 10

r=10;
theta = 0:0.1:360;
x=r*cosd(theta);
y=r*sind(theta);
plot(x,y,'-r')
title("circe x^2   y^2 = r^2")
xlabel("x-value")
ylabel("y-label")
legend('circle')

CodePudding user response:

You can do this:

function plotCircle(r)
    theta = 0:0.1:360;
    x = r*cosd(theta);
    y = r*sind(theta);
    plot(x,y,'-r')
    title("circe x^2   y^2 = r^2")
    xlabel("x-value")
    ylabel("y-label")
    legend('circle')
    axis square
end

and call the function as plotCircle(10).

enter image description here

  • Related