MathGroup Archive 2006

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

Search the Archive

Re: Formatted Output (Exporting Data)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64448] Re: [mg64415] Formatted Output (Exporting Data)
  • From: Pratik Desai <pdesai1 at umbc.edu>
  • Date: Fri, 17 Feb 2006 04:12:10 -0500 (EST)
  • References: <200602160805.DAA29874@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

tlhiv wrote:

>I'm trying to export the data obtained by evaluating a function at
>certain points.  The method that I'm currently using is:
>
>f[x_]:=x^2
>Export["foo.d",Table[{x, f[x]}, {x, -1, 1, 0.2}], "Table"]
>
>This generates a file "foo.d" that look like:
>
>-1   1
>-0.8   0.6400000000000001
>-0.6   0.36
>-0.39999999999999997   0.15999999999999998
>-0.19999999999999996   0.03999999999999998
>5.551115123125783e-17   3.0814879110195774e-33
>0.20000000000000007   0.04000000000000003
>0.4000000000000001   0.16000000000000006
>0.6000000000000001   0.3600000000000001
>0.8   0.6400000000000001
>1.   1.
>
>I would very much like to have "foo.d" look like:
>
>-1 1
>-0.8 0.64
>-0.6 0.36
>-0.4 0.16
>-0.2 0.04
>0 0
>0.2 0.04
>0.4 0.16
>0.6 0.36
>0.8 0.64
>1 1
>
>and with the delimeter being a TAB instead of a SPACE.  In particular,
>the precision used above is not so good.  I would like everything
>rounded off to, say, 6 significant digits.  An analogous C style output
>would be something like
>
>fprintf(fid,"%6f\t%6f\n,x,f)
>
>and is performed for each "element" of x.  Can this be accomplished
>easily with Mathematica?
>
>Thanks,
>
>Troy Henderson
>Assistant Professor
>Department of Mathematical Sciences
>252 Thayer Hall
>United States Military Academy
>West Point, NY  10996
>(845) 938-5649
>http://www.tlhiv.org
>
>  
>
Maybe something like this
data4=TableForm[Table[{x, f[x]}, {x, -1, 1, 
0.2}],TableHeadings->{Automatic,{"x","f[x]"}}]//Chop
SetDirectory["C:\\"]
Export["f.txt",data4,"Text"]

I have used txt I am not sure about the d extension...


Hope this helps

Pratik




  • Prev by Date: Re: Using a text editor like interface for Mathematica?
  • Next by Date: Re: Re: real newbie question
  • Previous by thread: Formatted Output (Exporting Data)
  • Next by thread: Re: Formatted Output (Exporting Data)