Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Convert long String to large Array


  • To: mathgroup@smc.vnet.net
  • Subject: [mg10299] Re: Convert long String to large Array
  • From: Bruce Wolk <bawolk@ucdavis.edu>
  • Date: Mon, 5 Jan 1998 03:47:19 -0500
  • Organization: University of California, Davis
  • References: <68n2qs$pmc@smc.vnet.net>

H. Neilson wrote:
> 
> Would someone lend us a helping hand please...........
> 
> We're reading an ASCII data file into Mathematica 3.0 on Windows95.  The
> data is delimited by spaces and consists of numbers 1-12, repeating 8
> times;
> a segment of which follows:
> 
> 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3....... This
> is "dummy" data, actual data will not be repetitive
> 
> The Head is List and its name is nofo.
> 
> We would like to take the data and generate a 12x8 array.
> 
> We thought the following would work, but it and various changes have
> not produced the desired result.
> 
> Table[noform[{N[j(j-1)+i]}],{j,8},{i,12}]
> 
> The idea was to specify the location within nofo from which to get a
> value and also specify the location in the new array to place that
> value.
> 
> Could someone explain why the above does not produce what we want and
> also suggest some code that will do the job?
> 
> Does anyone know of a text with extensive coverage on handling arrays
> with Mathematica?
> 
> Thank you very much!!
> 
> P.S.....One other issue was just brought to my attention.  What if we
> want to extend our new array to make it 15x8, keeping the existing
> array  as is, thus each line would look like 1 2 3 4 5 6 7 8 8 9 10 11
> 12 13 14  15.
> In essence, a 3x8 array is tacked onto the right side of our existing
> array.  (Again, we are not looking to generate the numbers: 13,14,15;
> rather to add  a 3x8 array of non repetitive data at some later date.)
> If your solution can be modified to do this, great.  If not, could you
> also offer a suggestion on this problem as well.
> 
> Again, thank you for your help.

The simplest way to read in a space delimited ascii file is to use
ReadList.  Assume your file name is "data."

info = ReadList["data", Number] 

will make info a one-dimensional list of all the data.  If you want to
break it up into rows of 12, you can use a template as follows

info = ReadList["data", Table[Number, {12}]]

Hope this is useful.

Bruce



  • Prev by Date: Re: Rotate3D bug solution
  • Next by Date: Re: Parametric & nonlinear equations system
  • Prev by thread: Re: Convert long String to large Array
  • Next by thread: Eulerian angles