Plot a moving dot inside a quiver plot that is constantly being updated
Mostra commenti meno recenti
I have the following code that will create a quiver plot (imagine a team of players in a football game) and I would like to update the position of the ball (a red dot).
x = rand(10);
y = rand(10);
direction = 3*rand(10);
u = sin(direction);
v = cos(direction);
H = quiver(x, y, u, v, 'filled', 'Marker', 'o', 'LineWidth', 1.8, 'AutoScaleFactor', .1);
for c = 0:100
% make a step
x = x + 5 * sin(direction);
y = y + 5 * cos(direction);
Xball = 10*rand();
Yball = 10*rand();
u = sin(direction);
v = cos(direction);
pause(0.5);
set(H, 'XData', x, 'YData', y, 'udata', u,'vdata', v, 'MarkerFaceColor', 'b');
%scatter(H, Xball, Yball, 12, 'm', 'filled'); % will complain about the axes
hold on;
scatter(Xball, Yball, 12, 'm', 'filled'); % will work but will keep showing all the balls
hold off;
drawnow;
end
The quiver plot will update correctly but I cannot add the ball, and make it change position on each iteration. What is the correct way of doing it?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!