1

I am trying to make an animation with circles obtained with the rectangle function in Matlab2013. In order to animate the plot, I tried using clf, drawnow and pause, but it does not seem to work. On the other hand, when I work with dots or lines, I use set and pause and it works fine, but I do not see a way to use these with rectangles.

Here, I show you how I tried to do it with drawnow. There are 1000 time steps, and at every time step I have stored the x and y coordinates of four circles.

%At every time step I would like to plot 4 circles. 
PosxProt = rand(1000, 4)
PosyProt = rand(1000, 4)

for i=1:1000
    clf
    hold on
    for j=1:4
        rP=0.345; %radius of the circles
        cP=[PosxProt(i,j) PosyProt(i,j)]; %center of the circles
        rectangle('Position',[cP-rP 2*rP 2*rP],'Curvature',[1 1],'facecolor','r') %plot circle
    end
    drawnow
    pause(0.05)

end
m7913d
  • 10,244
  • 7
  • 28
  • 56
Fisiquin
  • 69
  • 8

1 Answers1

1

You can parametrize the rectangle using the following equation:

 % 2*p and 2*q are the size of the rectangle
 t = 0:0.01:1;
 x=p*(abs(cos(t))*cos(t)+abs(sin(t))*sin(t))
 y=q*(abs(cos(t))*cos(t)-abs(sin(t))*sin(t))

Then plot the rectangle using comet:

 comet(x,y)

Also you can find more options for comet here.

OmG
  • 18,337
  • 10
  • 57
  • 90