Message Boards Message Boards

1
|
5687 Views
|
1 Reply
|
3 Total Likes
View groups...
Share
Share this post:

How to export data from a for loop into a file as a table

Posted 11 years ago
Hi,

I am trying to create a table with two columns made from output of mathematica. I have a for loop that looks like this:

For[t = 1, t < 800, t = t + 50, Print]

as well as another similar for loop that creates the same amount of data. I've tried exporting just one of the two columns using:

Export["test.dat", For[t = 1, t < 800, t = t + 50, Print], "Table"]

but when I try importing "test.dat" it comes up blank (just a {} ). What commands can I use to simply export the results of two (or any number for that matter) for loops as columns in a text file.

Thanks
POSTED BY: David Harrison
You can do this, for example:
Export["test.dat", Table[t, {t, 1, 800, 50}], "Table"]

Or a table with two columns:
Export["test.dat", Table[{t, t^2}, {t, 1, 800, 50}], "Table"]

Or a 20x20 matrix:
Export["test.dat", Table[i+j, {i, 20}, {j, 20}], "Table"]
POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract