Re: Writing/appending tables to CSV files?
- To: mathgroup at smc.vnet.net
- Subject: [mg48867] Re: Writing/appending tables to CSV files?
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Sun, 20 Jun 2004 02:39:19 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 6/19/04 at 4:31 AM, greenberg at ucdavis.edu (Jonathan Greenberg)
wrote:
>Whats the best way to initialize and write to a csv file in
>Mathematica, given a loop that produces a 1 x N vector each time
>(which I want saved) -- I want the final CSV file to be M x N,
>where M is the number of iterations of the loop and N is the length
>of the output vector. Thoughts?
The simplest way would be to build up a matrix with the results then write the matrix with all M vectors to a file using Export. For example
data=
Table[
Table[Random[],{5}],{9}]
puts a 9 x 5 array in data
This can be written to a CSV file by either
Export["filename", Transpose@data, "CSV"]
which will result with filename containing a 5 x 9 array in CSV format
It is also possible to write out each 1 x N vector to a file and later create a M x N CSV file. But this would involve more complicated code with more read/write operations and likely will run slower.
--
To reply via email subtract one hundred and four