Error with addpoints when trying to animate a trajectory following a marker
I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made?I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made? I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made? matlab MATLAB Answers — New Questions