Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Given the following List:

  lis =  { {-2.8336, -1.1088, -0.1232, 1.23493}, {-2.8336, -1.1088, 0.1232, 
      1.08433}, {-2.8336, -0.8624, -0.616, 
      1.04417}, {-2.8336, -0.8624, -0.3696, 
      1.10441}, {-2.8336, -0.8624, -0.1232, 1.17469}, {-2.8336, -0.8624, 
      0.1232, 1.09437}, {-2.8336, -0.8624, 0.3696, 
      1.43574}, {-2.8336, -0.8624, 0.616, 
      1.07429}, {-2.8336, -0.616, -0.8624, 
      1.26506}, {-2.8336, -0.616, -0.616, 1.43574} }

One can convert it to a table as follows: lis//TableForm

But that just works for displaying it in Mathematica. How can one easily save that list to a text file so that it appears as a table?

share|improve this question
    
To me, a table is more than a string of text, for example, of ASCII characters. It implies some sort of structure or formatting. For what applications would you like the output to appear as a table? –  David Carraher Mar 3 '13 at 4:59
    
@DavidCarraher, I just want to read in the data as a text file for a visualization program. Also to use it for other procedural programming languages that read text files in that format. –  RunnyKine Mar 3 '13 at 5:03
    
This was pretty obvious from looking up Export in the documentation. –  Verbeia Mar 3 '13 at 5:13

2 Answers 2

up vote 4 down vote accepted

I don't know if this will work for you, but you might try something simple such as

data = {
  {-2.8336, -1.1088, -0.1232, 1.23493},
  {-2.8336, -1.1088, 0.1232, 1.08433},
  {-2.8336, -0.8624, -0.616, 1.04417},
  {-2.8336, -0.8624, -0.3696, 1.10441},
  {-2.8336, -0.8624, -0.1232, 1.17469}, 
  {-2.8336, -0.8624, 0.1232, 1.09437}, 
  {-2.8336, -0.8624, 0.3696, 1.43574}, 
  {-2.8336, -0.8624, 0.616, 1.07429}, 
  {-2.8336, -0.616, -0.8624, 1.26506}, 
  {-2.8336, -0.616, -0.616, 1.43574}
};

Export[FileNameJoin[{$HomeDirectory, "Desktop", "test.csv"}], data]

This produces a file with the following content:

-2.8336,-1.1088,-0.1232,1.23493
-2.8336,-1.1088,0.1232,1.08433
-2.8336,-0.8624,-0.616,1.04417
-2.8336,-0.8624,-0.3696,1.10441
-2.8336,-0.8624,-0.1232,1.17469
-2.8336,-0.8624,0.1232,1.09437
-2.8336,-0.8624,0.3696,1.43574
-2.8336,-0.8624,0.616,1.07429
-2.8336,-0.616,-0.8624,1.26506
-2.8336,-0.616,-0.616,1.43574

share|improve this answer

A quick look at the documentation for Export reveals that Mathematica supports a range of Export formats and that there is a guide on how to import and export data in different formats.

In that guide it states:

Export["file", list, "Table"] writes out data separated by spaces, with numbers given in C or Fortran-like form, as in 2.3E5 and so on.

This documentation page might also be useful.

share|improve this answer
    
And add this question for formatting problems. –  Sjoerd C. de Vries Mar 3 '13 at 12:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.