-1
$\begingroup$

I wish to know how I can export a 3D-plot from Mathematica in a file format (e.g. ".dat"), and import it later with Matlab to generate the plot therein. In fact I have successfully achieved the opération for a 2d-plot using the following commands:

  • in Mathematica:

    Export[" file.dat", Plot[Function(x) , {x, a, b} ] ;
    
  • in Matlab :

    F=importdata(file.dat).  
    

    This command produces a two columns vector F with components (x, Function(x)), which i use to generate the plot in matlab.

Now, I don't know which file format and command are suitable to realize to same operation with a 3D-plot.

$\endgroup$
0
$\begingroup$

If all you need is the raw data there's no need to work from a plot, which is a complicated graphics expression. This should suffice:

dataFunction[t_,f_] := Sin[t] + Cos[f];
dataRanges={
  Range[0, 2 \[Pi], \[Pi]/25],
  Range[0, 2 \[Pi], \[Pi]/25]
  };
data = 
  Flatten[
   Table[1. {t, f, dataFunction[t,f]}, 
     {t, First@dataRanges}, 
     {f, Last@dataRanges}], 
   1];
Export["~/Desktop/test.dat", data, "TSV"]

That creates a tab-separated values (x, y, f(x,y)) .dat file you can work with. Just change dataFunction and dataRanges and you're good to go.

If you really want to work from a 3D plot you can scrape the points out like this:

plot = Plot3D[Sin[t] + Cos[f], {t, 0, 2 \[Pi]}, {f, 0, 2 \[Pi]}];
Export["~/Desktop/test.dat", 
 First@FirstCase[plot, _GraphicsComplex, None, \[Infinity]], "TSV"]
$\endgroup$
  • $\begingroup$ Thanks. It works for the creation of the data file. But, i'm still facing problems with building a 3D surface plot with the data in Matlab. Please, any idea of how this could be done ? $\endgroup$ – T. Arthur Dec 23 '16 at 19:53
  • $\begingroup$ In fact, my real problem is to reproduce the same graphic in Matlab. $\endgroup$ – T. Arthur Dec 23 '16 at 20:10
  • $\begingroup$ Unfortunately this is the Mathematica stack exchange. Perhaps this will help you. Simply import the points into Matlab from the TSV file then create a surface plot from these points. Perhaps you could also export the data as a .mat file. $\endgroup$ – b3m2a1 Dec 23 '16 at 20:43
  • $\begingroup$ Thanks a lot for the link. It's easy and perfect. $\endgroup$ – T. Arthur Dec 23 '16 at 22:34
  • $\begingroup$ If the answer is what you want, consider accepting it to show that the question need not be left open (people with better answers can still contribute theirs and you can change which is the accepted answer). $\endgroup$ – b3m2a1 Dec 24 '16 at 8:38

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.