Regarding this line of code:
scatter(H, Xball, Yball, 12, 'm', 'filled');
Each call to scatter will create a new scatter object. What you want to do is to create a single scatter object and then update the data in that single object. Something closer to this:
s = scatter(H, Xball, Yball, 12, 'm', 'filled');
for c = 0:game
s.XData = Xball;
s.YData = Yball;
end
It also looks you are trying to use H as both an axes and a quiver object. The scatter command can take an axes object as a first input, but an axes object does not have an XData or YData property.
I cannot run your code without more of the variables defined, but I attempted to update it based on what I think you are trying to do:
H = quiver(NaN, NaN, NaN, NaN)
AX = H.Parent;
hold(AX,'on')
S = scatter(NaN, NaN, 12, 'm', 'filled');
hold(Ax,'off')
for c = 0:game
x(3:end) = x(3:end) + speed * sin(direction);
y(3:end) = y(3:end) + speed * cos(direction);
Xball = rand();
Yball = rand();
u = sin(direction);
v = cos(direction);
pause(0.5);
set(H, 'XData', x(3:end), 'YData', y(3:end), 'udata', u,'vdata', v, 'MarkerFaceColor', 'b');
set(S, 'XData', Xball, 'YData', Yball);
drawnow;
end
2 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/389959-plot-a-moving-dot-inside-a-quiver-plot-that-is-constantly-being-updated#comment_548272
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/389959-plot-a-moving-dot-inside-a-quiver-plot-that-is-constantly-being-updated#comment_548272
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/389959-plot-a-moving-dot-inside-a-quiver-plot-that-is-constantly-being-updated#comment_548343
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/389959-plot-a-moving-dot-inside-a-quiver-plot-that-is-constantly-being-updated#comment_548343
Sign in to comment.