-5
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – DavidC
    Mar 3 '13 at 4:59
  • $\begingroup$ This was pretty obvious from looking up Export in the documentation. $\endgroup$
    – Verbeia
    Mar 3 '13 at 5:13
5
$\begingroup$

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

$\endgroup$
5
$\begingroup$

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.

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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