How to trace the end point of my vector without losing other plots?
5 次查看(过去 30 天)
显示 更早的评论
I have created a short animation using plot where I made a branch of 10 line segments. The branch is waving in the air. I want to only trace the end point without erasing the branch. I tried every posibilities with hold on-off switch. But it traces either the whole thing or erase the branch while tracing the end point. here is my animation. How do I tell matlab that don't specifically erase my end point, while refreshing the plot.
0 个评论
回答(1 个)
Jan
2021-11-13
编辑:Jan
2021-11-13
Do not delete obejcts and draw new ones, but keep the obejcts and modify the coordinates. If nothing is deleted, it is easy to keep lines in the diagram.
If you post your code, it would be easier to insert the required changes.
axesH = axes('XLim', [0, 100], 'YLim', [0, 100], ...
'NextPlot', 'add'); % As: hold on
pos = [10, 10];
dotH = plot(pos(1), pos(2), 'go', 'Markersize', 20);
for k = 1:100
pause(0.1);
newPos = randi([0, 100], 1, 2);
line([pos(1), newPos(1)], [pos(2), newPos(2)]);
set(dotH, 'XData', newPos(1), 'YData', newPos(2));
pos = newPos;
end
Every object is hold, but the dot is modified. This is even faster than recreaing the object for each frame.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!