# Importing text file to plot animation in 1D

I have .txt file with data that I want import into mathematica and then create a 1D animation/simulation of 3 curves.

The format of the .txt file is in columns of: 1. time 2. particle type 3. distance (x axis) 4. resultant value (y axis).

Here is an extract from the code:

153 0 252 -7.89389e-08
153 0 253 7.88583e-08
153 0 254 -7.87986e-08
153 0 255 7.87613e-08
153 1 0 -2.75981e-05
153 1 1 2.76022e-05
153 1 2 -2.76148e-05
153 1 3 2.76356e-05
153 1 4 -2.76647e-05
153 1 5 2.77025e-05
...
153 1 251 2.77025e-05
153 1 252 -2.76647e-05
153 1 253 2.76356e-05
153 1 254 -2.76148e-05
153 1 255 2.76022e-05
153 2 0 2.36682e-06
153 2 1 -2.36716e-06
153 2 2 2.36824e-06
153 2 3 -2.37002e-06
153 2 4 2.37253e-06
153 2 5 -2.37577e-06
153 2 6 2.3797e-06
153 2 7 -2.38439e-06
153 2 8 2.38982e-06
153 2 9 -2.39593e-06
153 2 10 2.4029e-06
153 2 11 -2.41052e-06
...


The file has 153600 rows and 4 columns.

What is a good format to import this file into mathematica and how would I simulate the curves in 1D w.r.t. time, for each of the 3 particle types on one plot?

The plot should look like this still image below, but as a moving animation, with the G, X and Y as particle types:

• Maybe like this: data=ReadList["file.txt",Number, RecordLists -> True][[All,{2,1,3,4}]]; particles = GroupBy[data, First]; ListPlot[Values[particles][[All,All,{2,3}]]] plots x(t) for all particles. For y(t) change {2,3} to {2,4}. – Alx Dec 6 '19 at 14:57
• @Alx. Thanks! I will try it out. However, what I really wanted was y(t) vs. x(t) in 1 dimension for the 3 particle curves. – Brendan Darrer Dec 6 '19 at 15:17
• OK, correction to meet your requirements: data = ReadList["file.txt", Number, RecordLists -> True]; groupped = GroupBy[data, {First, #[[2]] &}]; plots = Table[ListPlot[((Values /@ Values[groupped])[[All, All, All, {3, 4}]])[[i]]],{i, Keys[groupped]}];. Then you can use ListAnimate[plots], or export plots to animated gif. The idea is to group by time, then by particle for particular time (will result in nested Associations), then we take only {x, y} i.e. {3, 4} columns for each inner Association. Each Table element represents y(x) for specific time i for all particles. – Alx Dec 6 '19 at 16:00