Matlab - Plotting Circles

Hey guys (Hi)

I have the following problem:

Quote:

Write a function m-ﬁle, PlotCircles.m, that can accept as input a vector, r,

having positive entries, and plots circles of radius r(i) on the same axis. If no input value for r is speciﬁed, the default is to plot a single circle with radius r = 1. Test your function by using r = 1:5.

Hints: Matlab commands that might be useful for this problem include max, min and any.

My solution so far:

Quote:

Code:

`function PlotCircles(r)`

theta = linspace(0,2*pi,1000);

if nargin == 0

r = 1;

end

for i = min(r):max(r)

x = i*cos(theta);

y = i*sin(theta);

plot(x,y)

axis square

axis([-(r+1) (r+1) -(r+1) (r+1)])

end

However when I input a vector as follows:

Quote:

Code:

`EDU>> r = 1:5`

r =

1 2 3 4 5

EDU>> PlotCircles(r)

??? Error using ==> axis>LocSetLimits at 236

Vector must have 4, 6, or 8 elements.

Error in ==> axis at 96

LocSetLimits(ax(j),cur_arg);

Error in ==> PlotCircles at 14

axis([-(r+1) (r+1) -(r+1) (r+1)])

And then it seems to draw only the first circle. Any help is appreciated. :)