-5

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?

RunnyKine
  • 33,088
  • 3
  • 109
  • 176
  • 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? – DavidC Mar 03 '13 at 04:59
  • This was pretty obvious from looking up Export in the documentation. – Verbeia Mar 03 '13 at 05:13

2 Answers2

6

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.

Verbeia
  • 34,233
  • 9
  • 109
  • 224
6

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257