Re: Writing result of "Do" in a single List
- To: mathgroup at smc.vnet.net
- Subject: [mg55350] Re: [mg55305] Writing result of "Do" in a single List
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Sat, 19 Mar 2005 04:47:17 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi Laurent, > When I am calculating values with the > Do[expr, {i, imin, imax, di}] > expression, I get single values as a result that are a pain to export. > How can I write these values in a list that then can easily > be exported? Why not re-cast the calculation so that it produces a table? Tables can be exported (using Export). For example ival = Range[imin, imax, idel]; tbl = expr[#]& /@ ival; Export["filename", tbl, "Lines"]; or ival = Range[imin, imax, idel]; tbl = {#, expr[#]}& /@ ival; Export["filename.dat", tbl]; An alternative, depending on the complexity "expr", is to write to a file as you go through the loop. An example of this might be outf = OpenWite["filename", PageWidth->Infinity]; Do[ expr; Write[outf, expr], {i, imin, imax, idel} ]; The first option is usually preferred since functional programming is usually much quicker & easier to read than the Do loop. Regards, Dave.