How can I 'hold off' specific Field vector using "quiver" into a updated "drawnown" inside a plot?

13 views (last 30 days)
Hello!
I wanted to make an animation using "quiver" function. The problem is that the "drawnow" is plotting over and over the previous field vectors each iteration of 'for' loop ("overdrawning"). I wanted to "erase" the previous plots, and keep the last plot (updating plot to plot).
Some example:
%-------------//----------------------
(function1)
(plot1 the function above)
hold on
for idx=1:nImages
Ma=quiver(idx) over plot1
drawnow
hold off (erase only the previous quivers, not current quiver updated & plot1; so, hold the last quiver)
end
%---------//---------------------
The problem using 'hold off' is that it erases all plots and quiver, but the 'plot1' was erased also.
I've tried to use hold(Ma,'off'), but the error happened:
"Error using hold (line 52)
First argument must be an axes object."
I think it means that 'hold' doesn't accept "quiver", only common plottings.
If someone can help me about that I will be grateful!!
Thanks! (from Brazil)

Accepted Answer

Image Analyst
Image Analyst on 12 Dec 2021
You can put hold on to save the prior graphics and then plot some more, but if you want to delete these latter graphics you'll have to save their handles and call delete() on them.
hold on
for k = 1 : nImages
hQuiver = quiver(k) % Put quiver over plot1. Save it's handle so we can delete it later.
drawnow
pause(0.5); % Delay long enough to see it.
% Now get rid of it so it won't be there when we come to plot the next one.
delete(hQuiver) % (erase only the previous quivers, not current quiver updated & plot1; so, hold the last quiver)
end
hold off
%---------//---------------------
  2 Comments
Image Analyst
Image Analyst on 13 Dec 2021
@Igor Rocha you can make it faster by decreasing the amount of time it pauses:
pause(0.04); % or whatever.
or delete the pause line completely.

Sign in to comment.

More Answers (1)

Mitchell Thurston
Mitchell Thurston on 12 Dec 2021
I'm assuming you're calling quiver in the "quiver(x,y,u,v)" style, since you can't use 1 argument
% After plot 1 is made
hold on
Ma = quiver([NaN],[NaN],[NaN],[NaN]);
for i = 1:nImages
set(Ma, 'XData', x(i,:), 'YData', y(i,:), 'UData', dx(i,:), 'VData', dy(i,:));
drawnow
% would likely want to add a pause(0.1) here so you can see it
% changing in real time
end
I'm not sure what arguments you're using on quiver, so I used names that made sense. Hopefully this helps.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!