Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Table format gets lost while write to outputfile?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44786] Re: Table format gets lost while write to outputfile?
  • From: Bill Rowe <readnewscix at mail.earthlink.net>
  • Date: Thu, 27 Nov 2003 11:38:11 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 11/25/03 at 12:45 AM, lzhang1 at uci.edu (jc) wrote:

> I try to write out some data to a file. I need them to be in a table form.
> I.e. Each row is an instance, and each column is the value for each time
> point.

> I successfully use the below function to get the correct format in
> mathematica

> new = Table[trajectory[j][t], {j, 1, 11}, {t, 0, 100, 1}]

> datainfile = TableForm[new, TableHeadings -> {None, Automatic} ]

> The output looks good so far, it likes

> 1       2         3         4          5  ....
> 0.1     0.2       0.3       0.5        0.8
> 1.0     1.1       1.2       1.8        1.0
> 0.3     0.5       1.0       0.9        1.0
> ....

TableForm as well as the other output forms affects the display of data within Mathematica.

> however, when I type in
 
> datainfile >> outputfile

> The output file "outputfile" does not contain the correct format , it
> becomes like:
 
> TableForm[{{1., 2, 3, 4,
>    5,...},{0.1,0.2,0.3, 0.5,0.8},{1.0,  1.1,   1.2,1.8,1.0}....]

Exactly as it should be. The ">>" operator writes a Mathematica expression to an output file. And you have defined datainfile to be TableForm[...

> i am just wondering is there anyway to come across the problem and get the
> kind of format that I want in the output file?

Probably the simplest would be to use Export as in

Export["outputfile", new, "Table"]

This will have the effect of writing the numbers out separated by spaces with each row to a separate line in the file. However, it will not align the decimal points as TableForm does. If you want the output file to appear this way you will probably have to write a custom output routine.
--
To reply via email subtract one hundred and nine


  • Prev by Date: RE: How to use Rules from Solve and FindRoot
  • Next by Date: RE: change of a coefficient in a polynomial
  • Previous by thread: Re: Table format gets lost while write to outputfile?
  • Next by thread: subscribe and ask questions