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



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





  • Prev by Date: Re: How to draw several curves in different boxes ?
  • Next by Date: Re: reading with ReadList
  • Prev by thread: Re: Convert long String to large Array
  • Next by thread: Re: Convert long String to large Array