MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Nested Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28399] Re: Nested Lists
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Mon, 16 Apr 2001 03:28:50 -0400 (EDT)
  • References: <9b8ol0$7et@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Robert,
I have taken N = 2 below, and changed N to NN, since N is protected.

NN=2;

With your reading method

ReadList["temp.txt",{Number,Table[Number,{NN},{3}]}]

        {{1,{{2,3,4},{5,6,7}}},{2,{{3,4,5},{6,7,8}}}}

We can proceed:

(Flatten[#,1]&/@dat1)[[All,{1,3}]]

        {{1,{5,6,7}},{2,{6,7,8}}}

Changing the reading method slightly

ReadList["temp.txt",Prepend[ Table[Number,{NN},{3}],Number]]

        {{1,{2,3,4},{5,6,7}},{2,{3,4,5},{6,7,8}}}

allows us to use the simpler

%[[All,{1,3}]]

        {{1,{5,6,7}},{2,{6,7,8}}}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Robert Love" <rlove at neosoft.com> wrote in message
news:9b8ol0$7et at smc.vnet.net...
> 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
>




  • Prev by Date: Re: Mapping a scalar against a list
  • Next by Date: Re: inum error from NIntegrate?
  • Previous by thread: RE: Nested Lists
  • Next by thread: exporting a .bmp sequence of an animation