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.

Consider the following example of trying to export the following table:

Export["test.dat", {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}, "Table"];

Now I import to see what I get:

Import["test.dat", "Table"]
{{{1,,1}, {2,,2}}, {{3,, 3}, {4,,4}}}

which contains extra undesirable commas. I've trying making the data type a "List" but that possessing an issue in which elements are not separated by commas. How can I fix this problem so the the imported table is the same as I exported?

share|improve this question
    
If I only have the possibilty to Import as a txt how could I possibly get rid of the commas? –  RMMA Feb 20 at 8:15
add comment

4 Answers 4

up vote 4 down vote accepted

The problem is you are saving as text (you can see by looking at the FullForm of the Import[]). One way to fix it is to save to a .csv format, for instance

Export["test.csv", {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}]

Then you can import it back using

Import["test.csv"]

And you get the data you started with.

share|improve this answer
add comment

Another way:

Export["test.dat", {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}, "Table"];

Import["test.dat", "TSV"]
share|improve this answer
add comment

Another format especially suited for large amounts of multidimensional data is HDF (or also HDF5). It's overkill for your small example, but maybe you have larger sets in mind so that you could use this:

Export["test1.hdf", {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}];

Import["test1.hdf", {"Datasets", "Dataset1"}]

(* ==> {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}} *)
share|improve this answer
add comment

To get something Mathematica will like, use

Export["test.m", {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}]

This will produce a file with the contents:

(* Created by Wolfram Mathematica 8.0 : www.wolfram.com *)
{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}

share|improve this answer
add comment

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.