How to trace the end point of my vector without losing other plots?

16 visualizaciones (últimos 30 días)
Chirag Dudhat
Chirag Dudhat el 13 de Nov. de 2021
Editada: Jan el 13 de Nov. de 2021
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.

Respuestas (1)

Jan
Jan el 13 de Nov. de 2021
Editada: Jan el 13 de Nov. de 2021
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.

Categorías

Más información sobre View and Analyze Simulation Results en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by