Creating Animation in Scilab

2019-04-17 06:14发布

问题:

I am able to plot a point using the x and y coordinates using the following code.

figure(1);
plot(x(1),y(1),'o');
h_compound = gce();
h_compound.children.mark_size = 20;
h_compound.children.mark_background = 2;
h_axes = gca();
h_axes.data_bounds = [0,0;100,100];    

My program contains a loop which keeps on refreshing the coordinate values. Every time the loop is executed the point is plotted in the same graphic, such that the new points overlap the older ones. How do I make the old points disappear as the new points are plotted so that an animation-like sequence is generated?

回答1:

scf(1);clf;
x=linspace(0,10,100);
y=sin(x);

plot(x(1),y(1),"o")
h_compound = gce();
h_point=h_compound.children
h_point.mark_size = 20;
h_point.mark_background = 2;
h_axes = gca();
h_axes.data_bounds = [0,-1;10,1];  
realtimeinit(0.1);
for i=1:100
  realtime(i);//wait 0.1 second before drawing the new position
  h_point.data=[x(i),y(i)];
end