MATLAB: How to create x number of circles and then animate them

animatecircleforgraphloopMATLABplot

I want to let the user specify how many circles there are to be plotted, each circle having a different size and all of them are in the center of the plot. Then I want to animate them so each circle gets a random speed to a random direction in the 2D plot. Is this possible?
I made this function to generate n numbers of random triangles but I don't know how to animate them with a certain speed and direction.
function circles(n)
for i = 1:n
size = randi(100);
pos = -size/2;
rectangle('Position',[pos pos size size],'Curvature',[1 1]);
end

Best Answer

function circles(c)
rectangle('Position',[-250 -250 500 500]);
size =randi([1,100],1,c);
k=-size/2 ;
l=-size/2 ;
m=-10+20*rand(1,c);
n=-10+20*rand(1,c);
for i=1:20
for a =1:c
r(a)=rectangle('Position',[k(a) l(a) size(a) size(a)],'Curvature',[1 1]);
k(a)=k(a)+m(a);
l(a)=l(a)+n(a);
end
refreshdata;
pause(.1);
if i==20
continue
end
delete(r(1,:))
end
After hours of dedicated work , I just wrote it as a beginner Matlaber. This would do it .Cheers ;