MATLAB's drawnow doesn't flush -
is there reason matlab's drawnow wouldn't flush?
this code:
j=1; k = 1:length(p) = 1:n plot(p(k,j),p(k,j+1),'.'); j = j+2; end axis equal axis([-l l -l l]); j=1; drawnow end
(rungekutta4
own function wrote, , works ok, problem isn't there.)
the particles stay drawn on plot , don't overwritten every time loop executes.
how fix problem?
the proper , efficient way handle graphics. should vectorize plot
commands.
% example data make runnable l = 1; n = 10; % number of points p = 2*rand(1e2,n+1)-1; % initialize plot, first iteration h = plot(p(1,1:n),p(1,2:n+1),'.'); % plot first set of points , return handle axis equal; axis([-l l -l l]); hold on; % ensure axis properties fixed drawnow; % animate k = 2:size(p,1) % size safer in case % use handle update positions of plotted points set(h,{'xdata','ydata'},{p(k,1:n),p(k,2:n+1)}); drawnow; pause(0.1); % slow down animation bit make visible end
calling clf
and/or plot
on each iteration of animation causes many things in memory unnecessarily deleted , reallocated, resulting slower code. may result in flickering in cases.
Comments
Post a Comment