Array to plot regarding position, please help
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Simon
le 20 Nov 2013
Hi!
So, what is the difference between this question and http://www.mathworks.com/matlabcentral/answers/106889-simulation-for-an-array?
Réponses (1)
A Jenkins
le 20 Nov 2013
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 commentaires
A Jenkins
le 21 Nov 2013
Modifié(e) : A Jenkins
le 21 Nov 2013
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)
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!