How can I correct my function?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2018-2-15
Then please tell us, how you call this function. Do you click on the green triangle in the editor?
回答(1 个)
Jan
2018-2-15
Call it from another script or function or from the command window:
center = 23;
radius = 5;
[x, y] = getCircle(center,radius)
6 个评论
Jan
2018-2-15
@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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!