So far I have been solving non-linear pdes with NDSolve and then plotting the result with the in-built Plot3D and ContourPlots.

An example file can be found here.

This is a two part question with part 1 leading in to part 2.

Part 1

How do I interpret the interpolating function (how do I read it)?

For instance, I can "expand" the InterpolatingFunction with


This obviously has all the points that Plot3D plots with. How do I read this, say, row-wise or column-wise to make more sense of whats going on?

Part 2

How can I save this data to a .csv format or just some external file to use, say, gnuplot or some other plotting routine?

I have trid DumpSave etc . but the resulting huge files are generally not cross platform compatible.

  • $\begingroup$ Define "read it." Do you mean that you wish to read it yourself, or do you wish to have some other program (as you've implied) interpret it for you? (The latter obviously requires an understanding of the internal structure, but not necessarily the ability to read the internals yourself.) More specifically, why do you wish to do this? What are you using it for? $\endgroup$
    – rcollyer
    Commented Aug 20, 2012 at 14:58
  • $\begingroup$ @rcollyer I wish to do this (export data) because I am not a big fan of mathematica's Plot functions. When I say, "read", I mean, how is the data laid out? Should I look at it columnwise/rowwise? $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 15:04
  • $\begingroup$ Perhaps I am not getting this, but once you´ve got your InterpolationFunction up and running, you can extract and generate values according to your or your plotting software´s liking... $\endgroup$
    – Yves Klett
    Commented Aug 20, 2012 at 16:08
  • $\begingroup$ @YvesKlett HOW must I extract data, is the question. DumpSave didn't help. ONe person thinks I should use export. I'll try that soon. $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 16:10
  • 1
    $\begingroup$ Please help us by refining your question: What exactly do you want to achieve? How does your input look like (post working code)? How should the result look like? $\endgroup$
    – Yves Klett
    Commented Aug 20, 2012 at 16:47

2 Answers 2


It depends on what you want to do with your data afterwards

l = Flatten[
   Table[{{x, y}, x^2 + y^2}, {x, -1, 1, .1}, {y, -1, 1, .1}], 1];
f = Interpolation[l];

(* To export as a text file*)
 r = Flatten /@ Transpose[Flatten[#, 1] & /@ 
                       {InterpolatingFunctionGrid[f], InterpolatingFunctionValuesOnGrid[f]}]]

(* Export as a CSV file *)
Export["c:\\test.csv", r];

Mathematica graphics

Note: Please note that the above is needed if your function is expensive to calculate, because the following is a lot easier to type:

 Export["c:\\test.csv", Table[{x,y,f@x},{x,0,1,.1},{y,0,1,.1}]];

Also, you may export for other pieces of s...oftware. Like Excel:

(*I don't mean to be rude, but the following is for Excel 3D plots (OMG)*)
Export["c:\\test.xls", InterpolatingFunctionValuesOnGrid[f]]

Mathematica graphics

  • $\begingroup$ YOu weren't rude at all! I'll look into this. I am doing so right now. However, my interpolating function thingy is 6MB or more for my problem and I am having a tough time loading it and extracting data from it. Lots of curly brackets I don't know what to do with. And then there is the matter of how should I read this data? Which is X, Y and Z? $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 19:39
  • 1
    $\begingroup$ @DNA If you are really planning to plot this kind of thing in Excel, be prepared to suffer a lot. It's MUCH easier to do it in Mma. Go to Chat and ping me if you need help $\endgroup$ Commented Aug 20, 2012 at 19:43
  • $\begingroup$ No, not in excel. I was only wondering if I could extract data. The reason I want to is that I have literally 100s of cases that I run in mathematica and I can't extract the data out of mathematica. So if I need some data I don't have, I need to re-run my simulations which is quite the pain in the rear. $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 19:45
  • $\begingroup$ @DNA The Export[] before the Excel example in my code exports a CSV without braces $\endgroup$ Commented Aug 20, 2012 at 19:48
  • $\begingroup$ Noticed. However, it seems to entail a lot of trouble with mathematica commands that sound so foreign to me to just export the simplest of data cases. Wow. Sorry but I've been extremely frust. with mathematica's lack of easy export capabilities. $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 19:50

Interpolation stores it's data consistent with other Mathematica functions:

f = Interpolation[
   Flatten[Table[{{x, y}, Sin[x y]}, {x, 0, 1, .25}, {y, 0, 2, .25}], 
InterpolatingFunctionGrid[f] === 
 Table[{x, y}, {x, 0, 1, .25}, {y, 0, 2, .25}]
(* True *)

To export that raw data you could use Export

  • $\begingroup$ Ummm... there are a lot of curly brackets. How should I go about getting rid of all the curly brackets? $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 19:31
  • $\begingroup$ @DNA, Export[] will take care of that for you. Within Mathematica, however, the curly brackets are a necessity. $\endgroup$ Commented Aug 20, 2012 at 19:38
  • $\begingroup$ Export didn't take care of the curly brackets for me. I am thinking of writing a bash script to do that. $\endgroup$
    – dearN
    Commented Aug 20, 2012 at 19:39

Your Answer

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

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