Example 15
Importing and Manipulating
 Multi-Dimensional Data Files as Lists

Copyright © 1993 by Bill Titus, Carleton College, 
Department of Physics and Astronomy, Northfield, MN  55057-4025
September 6, 1993

Topics and Skills

Problem

0.0   1.0   0.0
	0.8   0.7   0.7
	1.6   0.0   1.0
	2.4  -0.7   0.7
	3.1  -1.0   0.0
	3.9  -0.7  -0.7
	4.7   0.0  -1.0
	5.5   0.7  -0.7
	6.3   1.0   0.0

Solution - Part a

Step 1 - Use a text editor or word processor to create an ASCII text file containing the desired three dimensional data.  Arrange the data, using tabs and/or spaces, into three columns and nine rows.  Save the data to the file  data2.dat.

Step 2 - Verify that your data file can be read by MMA by using the  !!  operator followed by the full path name of your file.  Do not enclose the file name in double quotes.

Comment 2

Solution - Part b

Step 1 -  Use  ReadList[]  to load  data2.dat  into MMA  as a set of reals.  However, only use one read type in  ReadList[]'s  argument.  Name the list  dataVer1.  What do you notice about the form of the final list produced by MMA?

Comment 1

Step 2 -  One way to produce the desired list of 3D points is to partition the list  dataVer1.  Locate the MMA command that will do this and create the desired list, naming it  dataVer2.

Step 3 - Another way to accomplish the task in Step 2 is to produce the desired list when you first read in the file.  The second argument in  ReadList[]  can be an expression or function of one or more of the basic "types", for example, {Real, Real, Real}.  Use this technique to obtain the desired list  dataVer2.

Comment 3

Solution - Part c

Step 1 - You'll now create a list consisting of the points  {t, x}.  To do so, you'll use the MMA function  Transpose[].  Find out about this function and then active the cell below and look closely at the code and the output.

Clear[tempList]
tempList = Transpose[dataVer2]
tempList[[1]]
tempList[[3]]
Transpose[{tempList[[1]], tempList[[3]]}]

Step 2 - Create the list  dataTX  consisting of the points  {t, x}  and plot the results on a 2D graph.

Comment 2

Solution - Part d

Step 1 - Create the list  dataTV  consisting of the points  {t, v}  and plot the results on a 2D graph.  Have your plot show both the points and lines connecting the points. (Hint:  produce two plots and then superimpose them using  Show[].)

Comment 1

Solution - Part e

Step 1 - The three dimensional phase plot can be created in two ways.  The most direct way is to use the function  ScatterPlot3D[]  found in the package  Graphics`Graphics3D`.  Load this package, find out about the function  ScatterPlot3D[]  and apply it to the list dataVer2.

Step 2 - The code in the following cell uses  ParametricPlot3D[]  to create the desired 3D phase plot.  It also uses the commands  Length[]  and  Round[].  Find out about the new commands, look over the code, and then activate the cell.

Clear[tempList]
tempList = Transpose[dataVer2];

ParametricPlot3D[
  {tempList[[1, Round[s]]],
   tempList[[2, Round[s]]],
   tempList[[3, Round[s]]]},
  {s, 1, Length[dataVer2]},
  DefaultColor -> RGBColor[0, 0, 1],
  AxesLabel -> {"t", "x", "v"},
  PlotLabel -> "Three Dimensional Phase Plot",
  FaceGrids -> All];

Comment 2

Save Your Notebook