Making a video showing trajectories of particles

8 次查看(过去 30 天)
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

采纳的回答

Greg Dionne
Greg Dionne 2019-4-26
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 个评论
S
S 2020-4-7
编辑:S 2020-4-7
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

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for USB Webcams 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by