Making a video showing trajectories of particles

조회 수: 8 (최근 30일)
Manny Kins
Manny Kins 2019년 4월 26일
편집: S 2020년 4월 7일
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
Manny Kins
Manny Kins 2019년 4월 29일
Thank you! This is a great starting point
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