Message Boards Message Boards

1
|
8242 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Formatting Output

Hi guys -

I'm currenlty learning mathematica; right now I'm working on learning how to output my solutions in usable formatting. I frequently would like to export to *txt or *.csv files.
Since working with Mathematica I've seen most of my outputs as lists. For usability/readibility I generally like my lists stacked as a column. Sometimes my results are lists themselves, as in the following example, from a discrete math problem:

x = 2;
l = Tuples[Range[x], x];
y = Tuples[(Range[x] /. n_ -> -n), x];
Length[l] + Length[y]
Column[{Column[l], Column[y]}]
In this example I'm interested in the number of signed permutations length x of Range 1 - x. I first output the number of permutations, then a list of all permutations. In Mathematica, it displays nicely using the column function:

However, I'd like to export it to a text file with each permutation being on a single line without the list braces. This is where I've been running into trouble.
I've tried a ReplaceAll function:
Column[{Column[l], Column[y]}] /. {{"{" -> ""}, {"}" -> ""}}
But this outputs more braces:


The other idea I had was just copy and pasting it to a text file, and do use a find-replace function there. I think what it wound up exporting was the internal representation of my data within Mathematica:


From this I'm getting the idea that the Column function doesn't convert my data to column format, but rather that it is a display command within Mathematica.
My question then is: what generic way is there for turning a list of results gotten in Mathematica into a nice stacked column format exported to a *.txt/ *.csv, without the curly braces? (I do know how to use the export command btw).
And is there a way I can write the data into a specific column (re: csv or xls exports)?

I do apologize if there's something very obvious I'm overlooking.
POSTED BY: Michael Senter
2 Replies
Posted 11 years ago
I think you can use export:
Export["~/Downloads/1.dat", Join[l, y]]

 

or you can use Grid function
Grid[Join[l, y]]
and select and copy as text and paste.

POSTED BY: xslittlegrass *
Interesting! When exporting straight it turns it into a columnar format. Nice. I previously tried exporting the Column[] function, and that just gave me a *.csv file reading 
Column[{{1, 1}, {1, 2}, {2, 1}, {2, 2}}]
Column[{{-1, -1}, {-1, -2}, {-2, -1}, {-2, -2}}]
Cool. Thanks!
POSTED BY: Michael Senter
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