Re: writing mathematica data to a tab delimited file??
- To: mathgroup at smc.vnet.net
- Subject: [mg18369] Re: writing mathematica data to a tab delimited file??
- From: "David Keith" <dkeith at sarif.com>
- Date: Wed, 30 Jun 1999 14:13:31 -0400
- Organization: Hevanet Communications
- References: <7l5t26$il6@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Mike, Others may well provide a maore economical solution, but this is what I have used. It also accepts arrays of dimension larger than and flattens them before use. In[11]:= writeArray[filename_, arrayname_] := Module[{makeStringList, outfile}, outfile = OpenWrite[filename]; makeDepth3[lst_] := Module[{x}, x = lst; While[Depth[x] < 3, x = {x}]; While[Depth[x] > 3, x = Flatten[x, 1]]; x]; makeStringList[lst_] := Flatten[{Drop[ Flatten[Transpose[{Map[ToString, lst], Table["\t", {Length[lst]}]}]], -1], {"\n"}}]; Scan[WriteString[outfile, Sequence @@ makeStringList[#]] &, makeDepth3[arrayname], {1}]; Close[outfile] ] In[12]:= t = Table[n - m, {n, 1, 5}, {m, 1, 5}] Out[12]= {{0, -1, -2, -3, -4}, {1, 0, -1, -2, -3}, {2, 1, 0, -1, -2}, {3, 2, 1, 0, -1}, {4, 3, 2, 1, 0}} In[13]:= writeArray["test.txt", t] Out[13]= "test.txt" In[14]:= !! test.txt 0 -1 -2 -3 -4 1 0 -1 -2 -3 2 1 0 -1 -2 3 2 1 0 -1 4 3 2 1 0 Mike wrote in message <7l5t26$il6 at smc.vnet.net>... > >I frequently read data into mathematica that has been given to me as a >two column tab delimited text file. Is their some way of saving a >mathematica list eg. > >mylist=Table[{1, x}, {x, 1, 10, 1}] > > >as a file in a tab delimited two column format > >1 1 >1 2 >1 3 >1 4 > >etc. > > > >to be read by other people in eg. excel or sigma plot? > >thanks > >Mike >