RE: Nested Lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg28392] RE: [mg28373] Nested Lists*From*: "tgarza01 at prodigy.net.mx" <tgarza01 at prodigy.net.mx>*Date*: Sun, 15 Apr 2001 00:13:44 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

This is a good exercise on list manipulation. Suppose your data in an Excel file (call it ptest.txt, for example) is as follows: {{1},{222,345,256},{121,321,43},{234,111,221},{684,322,345},{2},{324,356, 246},{322,543,553},{123,324,232},{78,543,456},{3},{432,567,345},{543,654, 789},{222,432,876},{567,890,321},{4},{321,325,654},{234,432,321},{567,332, 357},{345,543,222}} i.e. a time-stamp and a set of (in this example) 4 3D points. You read them in with In[1]:= a=ReadList["ptest.txt", Number, RecordLists->True]; This will take the fourth reading in each time-stamp: In[2]:= object4=#[[4]]&/@ Partition[Partition[Flatten[Rest[#]&/@Partition[Flatten[a],13]],3],4] Out[60]= {{684,322,345},{78,543,456},{567,890,321},{345,543,222}} Tomas Garza Mexico City Original Message: ----------------- From: rlove at neosoft.com (Robert Love) To: mathgroup at smc.vnet.net Subject: [mg28392] [mg28373] Nested Lists I'm confused about nested lists and how to select/extract data from them. I have a file of data I can use ReadList to read. The data is laid out like this: t1 x y z x y z x y z x y z t2 x y z x y z x y z x y z t3 etc. The data consists of a timestamp on a line and then the 3D position of each of the N objects for that time. N is always the same number so I read it it like this: ReadList["file",{Number, Table[Number, Number, Number,{N}]}] I'm doing this from memory since the computer w/Mathematica is at work. So I may not have every detail of the ReadList correct but what I end up with is {{t1,{{x,y,z},{x,y,z},{x,y,z},{x,y,z}}, {t2,{{x,y,z}... My question is now do I extract this suitable for graphing, that is, how do I turn this into something like a set of all the object #4 positions along with the time? I'm sure there is some combination of Flatten, Take, Transpose and Map that will do what I want. What is it? Also, is there a better way to use ReadList? I'm stuck with the file format but I can change how I read the data. All advice appreciated. Bob Love -------------------------------------------------------------------- Mail2Web - Check your email from the web at http://www.mail2web.com/ .