RE: How do I write tabular output?
- To: mathgroup at smc.vnet.net
- Subject: [mg74209] RE: [mg74133] How do I write tabular output?
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Wed, 14 Mar 2007 03:53:16 -0500 (EST)
- References: <200703130302.WAA10970@smc.vnet.net>
Hi Henning > I have a situation that I guess is rather usual: > > I have a list looking like this; > > {{C,1.23,2.34,0},{C,3.4,1.75,0.12},...} > > and I want to write an output file looking like this: > > C 1.23000 2.34000 0.00000 > C 3.40000 1.75000 0.12000 > etc. > > All tips and hints are very welcome! Should be straightforward shouldn't it. After all, if we can do this easily in Fortran, why not Mathematica? Anyway, given data = {"C", 10 * Random[], 5 * Random[], Random[]} & /@ Range[10]; We can define the helper function tstr[data_List] := Module[ {stmp}, stmp = ToString[PaddedForm[data[[#]], {9, 5}]] & /@ Range@Length@data ]; Then, tstr[data[[#]]] & /@ Range@Length@data; StringJoin[#] & /@ % Export["Henning.txt", %, "TABLE"] Should get you close to where you need to be. Depending on the magnitude of your data, you might also want to set ExponentFunction->(Null)& in PaddedForm[]. Regards, Dave.
- References:
- How do I write tabular output?
- From: "Henning Heiberg-Andersen" <henning.heibergandersen@gmail.com>
- How do I write tabular output?