RE: How to export txt files with variable name &
- To: mathgroup at smc.vnet.net
- Subject: [mg72588] RE: [mg72559] How to export txt files with variable name &
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Wed, 10 Jan 2007 03:39:12 -0500 (EST)
Hi Cham,
> I need to use the operation
> D0[Export["Coord_n.txt", Coord[n], "Table"], {n, 0, 3}]
>
> with a variable name. I want Mathematica to write down
> several files with names likes this (as much names as there
> are values for the variable "n") :
>
> Coord_0.txt, Coord_1.txt, Coord_2.txt, Coord_3.txt
>
> How can I do that ?
You'll need to convert the numbers (in your case, array indicies) to
strings, so you can join them to strings to form the file name.
ofile = StringJoin["Coord_", ToString[#], ".txt"] & /@ Range[3]
You can then write your data using
Export[ofile[[#]], Coord[[#]], "Table"]& /@ Range[3]
You rarely need Do[].
Regards,
Dave.