Array to plot regarding position, please help

2 次查看(过去 30 天)
Hello there,
I am having a hard time with something.
I have an array of positions of 5 particles.
-2.0000 5.0000 9.0000
1.0000 2.0000 1.0000
1.0000 2.0000 4.0000
2.0000 4.0000 5.0000
2.0000 4.0000 9.0000
7.9593 7.3679 28.5506
3.5556 2.6725 12.5232
20.4053 11.7222 12.2861
7.0142 9.7688 13.4013
8.3092 12.7684 18.8180
18.0262 10.7468 46.1048
6.9414 4.9151 24.8694
38.4836 21.5052 21.2306
13.4649 18.3509 27.2144
14.6882 21.1662 28.1150
28.0050 14.4318 63.0786
10.7245 7.9287 37.3743
56.1209 31.2706 30.3044
29.4162 48.6415 47.9855
20.3663 27.7720 36.8458
37.9202 18.2548 79.7830
14.7593 11.4279 49.8749
73.5533 41.0208 39.4236
45.2485 78.5777 68.5677
26.0782 34.3742 45.5945
47.7897 22.1520 96.3300
18.9727 15.2688 62.3179
90.8710 50.7579 48.5628
61.0552 108.4253 89.1036
31.8039 40.9624 54.3531
Where each column represents X, Y, Z.
The array is somewhat confusing.
It is set up as follows: The first row is position of particle 1 at time=0 The second row is position of particle 2 at time=0 ... The fifth row is position of particle 5 at time=0 The sixth row is position of particle 1 at time=1 ... The last row is position of particle 5 at time = 5
Hope this makes sense.
Now I want to plot particles 1-5 from time=0-5
How can I do this?
Also is it possible to animate the progression of the particles? Thanks!

回答(1 个)

A Jenkins
A Jenkins 2013-11-20
To make your matrix "less confusing" you can reshape it into a 3d matrix. For example:
myarray3=permute(reshape(myarray',3,5,[]),[3,1,2])
This would show the data grouped so you can easily see the position of the 5 particles at each time step.
myarray3(:,:,1) =
-2.0000 5.0000 9.0000
7.9593 7.3679 28.5506
18.0262 10.7468 46.1048
28.0050 14.4318 63.0786
37.9202 18.2548 79.7830
47.7897 22.1520 96.3300
myarray3(:,:,2) =
1.0000 2.0000 1.0000
3.5556 2.6725 12.5232
6.9414 4.9151 24.8694
10.7245 7.9287 37.3743
14.7593 11.4279 49.8749
18.9727 15.2688 62.3179
etc...
Then you could use a for loop to go through each of the myarray(:,:,mytime) and plot the data. (Perhaps you want to use scatter3()...) Simon helped you out with how to do the animation in the post that he linked to.
  2 个评论
Nathan
Nathan 2013-11-21
Ok I have reorganized my data. But when I try to plot it for the first particle using:
for j=1:time
hold on
plot3(pos(1,1,time),pos(1,2,time),pos(1,3,time),'-')
F(j)=getframe;
end
movie(F)
The figure just resizes its axis and doesnt display anything really.
using the scatter3 just makes the data points flash all at once. There is no smooth animation from one frame to the next. Seems like all the data just gets dumped at once. I'm new to this so bare with me.
A Jenkins
A Jenkins 2013-11-21
编辑:A Jenkins 2013-11-21
1) To view the plot in 3d:
view(3)
2) To force the axis to stay the same size every time
axis([XMIN XMAX YMIN YMAX ZMIN ZMAX])
3) To plot all the particles instead of just the first one (and color code them):
scatter3(pos(:,1,time),pos(:,2,time),pos(:,3,time),[],jet(size(pos,1)),'filled')
4) To slow down the time between executing commands (if needed)
pause(1)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by