Re: Convert long String to large Array
- To: mathgroup@smc.vnet.net
- Subject: [mg10293] Re: Convert long String to large Array
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Mon, 5 Jan 1998 03:47:15 -0500
- References: <68n2qs$pmc@smc.vnet.net>
H. Neilson wrote: > 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. Is this of use? WriteString["nofo","1 2 3 4 5 1 2 3 4 5 1 2 3 4 5"] ReadList["nofo",Table[Number,{5}]] {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}} arr = % To convert to a 5 by 3 matrix: Transpose[arr] {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}} To extend rows of arr ext = {{6,7},{6,7},{6,7}}; MapThread[Join[#1,#2]&, {arr,ext}] {{1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 5, 6, 7}} or Flatten/@Transpose[{arr,ext}] {{1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 5, 6, 7}} -- Allan Hayes Training and Consulting Leicester, UK hay@haystack.demon.co.uk http://www.haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44 (0)116 271 8642