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

10 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

Image Analyst
Image Analyst le 12 Déc 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 commentaires
Igor Rocha
Igor Rocha le 13 Déc 2021
That way it worked, despite being little slowly. I think it's because the code is big (at least 60 variables updating into workspace each iteration).
I'm thinking a way to optimize te code time, putting a minimum amount of variables updated into the loop, or changing the structure of code according to the Mitchell's comment.
Anyway, thanks for the answer!
Image Analyst
Image Analyst le 13 Déc 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.

Connectez-vous pour commenter.

Plus de réponses (1)

Mitchell Thurston
Mitchell Thurston le 12 Déc 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.

Catégories

En savoir plus sur Vector Fields dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by