1
$\begingroup$

I have a 3D table that I'm able to plot using ListPlot3D, but when I export the table to an excel file and try to import the saved data, the format is different. The imported table seems to have additional commas everywhere, e.g.:

 TableT = Parallelize[
   Table[{x, y, Func[x, y]}, {x, -5.0, 5, 0.1}, {y, -5.0, 5, 0.1}]];
 Export["C:\\Users\\Desktop\\Research \
       Folders\\Rich\\MATHEMATICA ROUTINES\\Table.xls", TableT, "Table"];

 SampleTable = 
   Import["C:\\Users\\Desktop\\Research \
       Folders\\Rich\\MATHEMATICA ROUTINES\\Table.xls", "Table"];

And a sample of the output looks like:

    {{"{-1.,", "-1.,", "-1.682941969615793}", "{-1.,", "-0.7,", 
      "-1.4481056235651328}", "{-1.,", "-0.4,", "-1.0839143149837285}", 
      "{-1.,", "-0.10000000000000009,", "-0.6229001688139496}", "{-1.,", 
      "0.19999999999999996,", "-0.10624420571720333}", "{-1.,", "0.5,", 
      "0.4199022358543263}", "{-1.,", "0.7999999999999998,", 
      "0.9085400612713314}"}, {"{-0.7,", "-1.,", "-1.4481056235651328}", 

When I use this approach for 2D plots, it seems to work fine. Can someone explain why this isn't working for my 3D data?

$\endgroup$
3
  • 3
    $\begingroup$ be aware by specifying "Table" you are overriding recognition of the "xls" extension, so not writing an excel file $\endgroup$
    – george2079
    Apr 30, 2015 at 2:38
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Apr 30, 2015 at 2:40
  • $\begingroup$ You might want to consider using general paths (e.g. $HomeDirectory) for future code examples, this will be more convenient for users not sharing your exact directory structure. $\endgroup$
    – Yves Klett
    Apr 30, 2015 at 5:55

1 Answer 1

2
$\begingroup$

As @george2079 has already pointed out, you are causing confusion in the Import and Export formats by adding the "Table" option.

Try the following instead:

tableT = Parallelize[
   Table[{x, y, func[x, y]}, {x, -5, 5, 1}, {y, -5, 5, 1}]
   ];
Export["table.xls", tableT];

sampleTable = Import["table.xls"][[1]];

TableForm@sampleTable

(*
-5. -5. func[-5, -5]
-5. -4. func[-5, -4]
-5. -3. func[-5, -3]
-5. -2. func[-5, -2]
-5. -1. func[-5, -1]
-5. 0.  func[-5, 0]
-5. 1.  func[-5, 1]
-5. 2.  func[-5, 2]
-5. 3.  func[-5, 3]
-5. 4.  func[-5, 4]
-5. 5.  func[-5, 5]
*)

You should also note that, when working with Excel files, Import returns a list of lists. Each first-level element of the list corresponds to a sheet in the Excel file. To get to your list, you want to take the first component of that list of lists. This is what the [[1]] accomplishes above. Equivalently, you could write First@Import[...], or you can also access the sheet contents by name:

Import["table.xls", {"Sheets", "Sheet1" }]

As an aside, you should avoid using uppercase names for your variables to avoid any possible conflicts with built-in functions, whose names always start with an uppercase letter. I modified your variables names accordingly.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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