Plot a moving dot inside a quiver plot that is constantly being updated
이전 댓글 표시
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?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!