Effacer les filtres
Effacer les filtres

Making a video showing trajectories of particles

11 vues (au cours des 30 derniers jours)
Manny Kins
Manny Kins le 26 Avr 2019
Modifié(e) : S le 7 Avr 2020
I have some X, Y and T (time) co-ordinates for my particles (attached) and I want to plot and make a video of all of my particle trajectories on an X Y axis showing thier respective "motion" through time. Is there a way to do this using data of this type? I have looked into the function comet() which does something similar but it does not take into account time of particle "entrance" so to speak. So if a particle appears a certain time after another, it does not take this into account (to my knowledge at least). Any ideas?
A simple example of the trajectories:
Particle 1
Trajectories(1).T = 0:0.1:1;
Trajectories(1).X = [45, 46, 48, 49, 50, 61, 63, 64, 63, 60, 61]
Trajectories(1).Y = [10, 12, 11, 13, 15, 16, 18, 20, 19, 22, 21]
Particle 2
Trajectories(2).T = 0.5:0.1:1;
Trajectories(2).X = [10, 14, 12, 14, 13, 11]
Trajectories(2).Y = [30, 32, 31, 33, 34, 36]
And so I would want to plot both of these particle positions on an X Y plane with timesteps of 0.1, taking "entrance" time into consideration (here particle1 enters at time 0 and particle2 enters from time 0.5)
Thanks

Réponse acceptée

Greg Dionne
Greg Dionne le 26 Avr 2019
This should get you started:
load Trajectories.mat
hAxes = newplot;
colors = lines(10);
axis(hAxes,[0 1300 0 1100])
for i=1:10
hLine(i) = animatedline(hAxes,'Color',colors(i,:));
hText(i) = text(hAxes,NaN,NaN,num2str(i),'VerticalAlignment','bottom');
end
maxtime = max(horzcat(Trajectories(:).T));
for t = 0:.1:maxtime
for i=1:10
idx = find(Trajectories(i).T==t,1,'first');
if ~isempty(idx)
x = Trajectories(i).X(idx);
y = Trajectories(i).Y(idx);
addpoints(hLine(i),x,y);
hText(i).Position = [x y];
end
end
title(hAxes,sprintf('T = %6.1f',t));
drawnow
end
  2 commentaires
Manny Kins
Manny Kins le 29 Avr 2019
Thank you! This is a great starting point
S
S le 7 Avr 2020
Modifié(e) : S le 7 Avr 2020
Hi, How can I change this code if I have particle trajectories for different time frames.
Ex:
t=0
Particle X Y Z
1 0 0 0
2 0 0 0
t=1
Particle X Y Z
1 0.1 0 .2 0.1
2 -0.1 0.1 0.1
so on..
Thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 29 Avr 2019
Attached is a demo where I did some stuff in an axes and made the result into a movie.

Catégories

En savoir plus sur MATLAB Support Package for USB Webcams dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by