Re: formatted table output to ascii file
- To: mathgroup at smc.vnet.net
- Subject: [mg110415] Re: formatted table output to ascii file
- From: "Huber, Daniel" <dh at metrohm.com>
- Date: Thu, 17 Jun 2010 02:03:37 -0400 (EDT)
- References: <gpnseu$gqd$1@smc.vnet.net> <gpqg6l$5of$1@smc.vnet.net> <4284bd88-a5aa-40a4-b91e-826d7c2ba52b@30g2000vbi.googlegroups.com>
Hi,
make all you numbers precision numbers (e.g. using N) otherwise
Mathemaitca will try hard to give an exact representation. Further
the problem with the lone "e" is solved by e.g.:
Export["d:/tmp/t.txt",
ScientificForm[TableForm[table], 4,
NumberFormat -> (Row[If[#3 == "", {#1}, {#1, "e", #3}]] &)],
"String"];
cheers Daniel
-----Urspr=FCngliche Nachricht-----
Von: Bence Kocsis [mailto:bkocsis at gmail.com]
Gesendet: Mi 16.06.2010 00:47
An: Huber, Daniel
Betreff: Re: formatted table output to ascii file
Neither of these solutions work for a table with small numbers like
10^-7.
For example, consider
table = {{10^-6, 0.0000243729, 0.0000759669, 0.00187499}, {-2.,
0.0613641, 0.0827868, 0.0831174}, {0.4, 0.317162, 0.307924,
0.33977}}
Then the kuh functions give a file with:
1.0000
-------------
1000000.0000 2.437e-05 7.597e-05 1.875e-03
-2.0000 6.136e-02 8.279e-02 8.312e-02
0.4000 3.172e-01 3.079e-01 3.398e-01
while that of dh has the same same problem but it also screws up the
-2.0 element:
1e
--------
1000000e 2.437e-5 7.597e-5 1.875e-3
-2.e 6.136e-2 8.279e-2 8.312e-2
4.e-1 3.172e-1 3.079e-1 3.398e-1
Any solution in this case?
On Mar 18 2009, 5:51 am, dh <d... at metrohm.com> wrote:
> Hi,
>
> try e.g. ScvientificForm with Table:
>
> Export["d:/tmp/t.txt",
>
> ScientificForm[TableForm[d], 4,
>
> NumberFormat -> (Row[{#1, "e", #3}] &)], "String" ]
>
> hope this helps, Daniel
>
> kuh... at gmail.com wrote:
> > For the life of me I just cannot figure out how to get Mathematica =
to
> > produce nicely formatted (C or Fortran format) output of a 2D table =
of
> > numbers to an ASCII file.
>
> > Let's say I've got this table:
>
> > {{-6., 0.0000243729, 0.0000759669, 0.00187499},
> > {-2., 0.0613641, 0.0827868, 0.0831174},
> > {0.4, 0.317162, 0.307924, 0.33977}}
>
> > I'd like the resulting file to correspond to this C format string
> > "%5.2f %10.3e %10.3e %10.3e\n", i.e. to look like this:
>
> > -6.00 2.437e-05 7.597e-05 1.875e-03
> > -2.00 6.136e-02 8.279e-02 8.312e-02
> > 0.40 3.172e-01 3.079e-01 3.398e-02
>
> > I tried Export["file.dat",table], but got this mess:
>
> > -6. 0.00002437286669095962 0.0000759669270937278
> > 0.0018749887943499436
> > -1.9999999999999998 0.06136412066687522
> > 0.08278680554897219 0.08311737741506361
> > 0.40000000000000036 0.31716209930168276
> > 0.3079237859649251 0.3397696229714295
>
> > I also tried pre-formatting with something like
>
> > newdata = Map[ToString[PaddedForm[#, {6, 4}]] &, table, {2}];
>
> > but my mathematica-fu isn't good enough to generalize this to the
> > desired format.
>
> > Any help would be greatly appreciated!
>
> > mike