MathGroup Archive 1998

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

Search the Archive

Re: Convert long String to large Array



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.

I assume that noform is the same array as nofo previously mentioned and
that you intend noform[{N[j(j-1)+i}]  to be an array element of some
sort.

1- if you want to specify an array element, then you use double square
brackets (noform[[1,2]], not noform[1,2]). 2- array elements are
integers, so putting the N[] function to convert the element into a
real number is a bad idea. 3- I see no reason for the curly braces in
this case.


Based on the above, I would use noform[[j(j-1)+i]].

You might also check out the functions Take, List, Transpose, TakePart,
Partition, Flatten, Map etc.  Mathematica tends to be more efficient
using operator paradigm programming rather than procedural
programming(such as Do loops and Table functions)

Until you get the hang of mathematica, I recommend making a little cheat
sheet for yourself with basic syntax rules, such as are found in the
mathematica book section 1.2.5.  In my first few months of programming,
I found such a cheat sheet very helpful since I had the tendency to use
bracketing more appropriate for FORTRAN or C.

-- 
Remove the _nospam_ in the return address to respond.



  • Prev by Date: Re: Celestial Mechanics
  • Next by Date: Re: Rotate3D bug solution
  • Prev by thread: Convert long String to large Array
  • Next by thread: Re: Convert long String to large Array