MathGroup Archive 2007

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

Search the Archive

Re: How do I write tabular output?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74191] Re: How do I write tabular output?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 14 Mar 2007 03:43:31 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <et5487$an6$1@smc.vnet.net>

Henning Heiberg-Andersen wrote:
> Hi,
> 
> 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!
> 
> Best regards
> Henning Heiberg-Andersen
> 

First, we format the numbers and convert them to strings (if we do not 
do this last step, we end with a file full of PaddedForm[...] since 
PaddedForm is a wrapper that change the display but not the evaluation). 
Then, we write the resulting table into a file. Finally, we read the 
file from within Mathematica.

In[1]:=
lst = {{C, 1.23, 2.34, 0}, {C, 3.4, 1.75, 0.12}};
data = Map[ToString[PaddedForm[#1, {6, 5}]] & , lst, {2}];
Export["myfile", data, "Table"];
!!myfile

 From In[1]:=
C    1.23000    2.34000    0.00000
C    3.40000    1.75000    0.12000

HTH,
Jean-Marc


  • Prev by Date: Re: Interpolating Function
  • Next by Date: Re: Replacement question
  • Previous by thread: Re: How do I write tabular output?
  • Next by thread: Noob evaluation question