Reputation: 31567
I have a set of (x,y)
coordinates that describe the trajectory of an object. I'd like to animate this trajectory using GNU Octave.
The data set is quite large so I won't be able to redraw the entire plot at every iteration if I want the animation to be smooth. What functions are there that would allow me to "update" a plot rather than redraw it?
Also, I have another set of (vx,vy)
points, which describe the speed of the object. I'd like my animated trajectory to take speed into account. What function should I use to have the program sleep for a couple of milliseconds as to make the trajectory animate at the same speed as the object?
(I already know Octave has functions such as comet
, but I need to write my own animator.)
Edit: Here's what I have up until now. I expected this to run too fast and require me to use pause
, but it's still pretty slow (x
and y
have 10001 elements).
bounds = [min(x) max(x) min(y) max(y)];
axis(bounds);
hold on
for k = 2 : length(x)
plot(x(k-1:k), y(k-1:k));
drawnow("expose");
end
hold off
Upvotes: 4
Views: 4863
Reputation: 1
I think you are looking for the "hold" command. holding the plot keeps all previous data on the plot and the new data is added on top.
Upvotes: 0
Reputation: 15910
You can use the set
command to change just the XData
and YData
data for a certain plot object h
:
h = plot(my_xdata(0),my_ydata(0))
for i_=1:length(my_xdata)
set(h, 'YData', my_ydata(i_))
set(h, 'XData', my_xdata(i_))
pause(sqrt(vx(i_)^2+vy(i_)^2))
end
The pause(x)
command pauses for x
seconds, which can be less than 1.
Upvotes: 6