I have a large array in MATLAB specifying the positions in 2D of many particles. Each row corresponds to a particle. The 2n-1 and 2n 'th columns give the x and y coordinates of the particle at a given time, and the 2n+1,2n+2 'th columns give the coordinates at the next time interval. I am trying to plot all of these points, joined, so as to show the trajectories of the particles on one plot, but am not sure what the arguments should be for the plot command in this case.
0
votes
1 Answers
0
votes
Try the following code. The first six lines create a miniature version of your large array. Please tell me if I misread its arrangement.
% x,y x,y x,y x,y
p1 = [ 1,2, -1,3, -2,6, -3,7]; % positions of particle 1
p2 = [ 2,3, 2,4, 3,6 3,8]; % positions of particle 2
p3 = [-1,-3, 0,-1, 1,0, 2,2]; % positions of particle 3
ps = [p1;p2; p3]; % "large array"
px = ps(:,1:2:end)'; % particles' x-positions
py = ps(:,2:2:end)'; % particles' y-positions
plot(px,py)