How can I correct my function?

10 views (last 30 days)
Emma Pineiro
Emma Pineiro on 15 Feb 2018
Commented: Emma Pineiro on 15 Feb 2018
I am trying to make a function called getCircle that takes the inputs (center, radius)
my code looks like this:
function [x,y] = getCircle(center,radius)
p = 0:0.01:2*pi
x = cos(p)* radius + center(1)
y = sin(p)* radius + center(2)
end
when I try and run the function it tells me that i don't have enough input arguments.
This is the assignment, for clarification:
Write the function getCircle which is called as [x,y]=getCircle(center,radius) to get the x and y coordinates of points that fall on a circle. The circle should be centered at center (2-element vector containing the x and y values of the center) and have the provided radius. The function should return x and y such that a call to plot(x,y) will plot the circle. Note that going around a circle centered on the origin is going around from angle t = 0 to 2. In this case the x and y coordinates on a unit circle centered on the origin of radius 1 are x(t ) = cos (t )and y(t) = sin(t). The points can be scaled to the correct radius by multiplying by radius. The point can translated to have a center other than the origin by adding the center to each point. Write a program that uses getCircle to draw circles and makes a plot with 3 circles of radius 1,3,5 centered on (6,6) and 3 circles of radius 1,3,5 centered on (-6,6). The circles of radius 1,3, and 5 should be of different colors, and should use the same color for each value of radius in the two sets of circles.
  1 Comment
Jan
Jan on 15 Feb 2018
Then please tell us, how you call this function. Do you click on the green triangle in the editor?

Sign in to comment.

Answers (1)

Jan
Jan on 15 Feb 2018
Call it from another script or function or from the command window:
center = 23;
radius = 5;
[x, y] = getCircle(center,radius)
  6 Comments
Jan
Jan on 15 Feb 2018
@Emma: I have posted the code to call your getCircle function already. Walter has posted it also. Now you still write "it wont run the function getCircle." The examples we gave do run your function. So please explain, what you are doing instead of the suggested code.
Emma Pineiro
Emma Pineiro on 15 Feb 2018
I talked with my professor, and there was something wrong with the file itself. I deleted the file and called it in a different script and everything worked! Thank you so much for all your help.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!