Plot trajectory along with tracer colors
Mostrar comentarios más antiguos
I am dealing with a particle moving in a 2D space, and I've successfully recorded its position coordinates. Now, I aim to visualize the particle's trajectory overlaid onto video frames. The color of the trajectory should evolve over time, with only the current positions reflecting the changing colors. However, I'm facing an issue where the tracer line disappears as time progresses, despite the changing colors of the current particle positions in the trajectory. Here is my code.
data = load('data.dat');
frames=200;
colormapJet = colormap(jet(size(data, 1)));
for i = 1:frames
img = imread(sprintf('%04d.jpg', i));
imshow(img, []);
hold on
x = data(i, 1);
y = data(i, 2);
if i > 1
x_prev = data(i - 1, 1);
y_prev = data(i - 1, 2);
plot([x_prev, x], [y_prev, y], '-o','color', colormapJet(i, :), 'LineWidth', 4.0);
end
drawnow;
hold off
end
data= my xy co-ordinates
img =frames
I want somethin like this as shown in image below. I want to make a video along with the frames and trajectory lines which leads to something like this.
As soon as I comment the below part, it traces trajectory the way i want, but I can't overlay the images alone with the trajectory.
img = imread(sprintf('%04d.jpg', i));
imshow(img, []);

Any help would be appreciated. Thanks
1 comentario
Alakesh Upadhyaya
el 8 de Mzo. de 2024
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
