# Native function in Mathematica export functions from Mathematica to MATLAB

Is there any native function in Mathematica (not ToMatlab) that I can export a function from Mathematica to MATLAB, to Paraview or to any plotting software?

Clarification: I want to export something like f[x_,y_,z_]:=Sin[x]Sin[y z] e^z;

Edit: Here why I want to move to MATLAB. I will have a 4D system and use ListPlot3D, SliceListPlot in Mathematica and I need to evaluate the function.

f[x_, y_, z_] :=
Cos[Pi*x^3] + Cos[Pi*x^3]*Cos[Pi*x^3] + Cos[Pi*z^3] +
Sin[x + z] x^2 + y^2 + z^2 +
Exp[Cos[Pi*x^3] Cos[Pi*x^3] + Cos[Pi*z^3] + Sin[x + z] x^2 + y^2 +
z^2];
AbsoluteTiming[
data = Table[
Evaluate@N[f[x, y, z]], {x, 0, 1, 0.0025}, {y, 0, 1, 0.0025}, {z,
0, 1, 0.0025}];]


and Matlab version

x=0:0.0025:1;
y=x; z=x;
tic;[X,Y,Z] = meshgrid(x,y,z);F = cos(pi*X.^3) +
cos(pi*X.^3).*cos(pi*X.^3) + cos(pi*Z.^3) + sin(X + Z).*X.^2 + Y.^2
+...
Z.^2 + exp(cos(pi*X.^3).*cos(pi*X.^3) + cos(pi*Z.^3) + sin(X + Z).*X.^2
+ Y.^2 + Z.^2);
toc;


Mathematica takes 37 seconds and MATLAB takes 14 seconds. I am aware the 37 seconds nothing but my function is much longer, it is 4D. Thanks. Erdem

Ps: My functions are generally really long trigonometric functions.

• Do you mean to export a function definition or to export some of the outputs of executing a function ? – High Performance Mark Nov 29 '18 at 16:29
• To any plotting software? Is there a reason the plotting in Mathematica won't work for you? If you're really set against using Mathematica to do the plotting, you could check out MATLink. It allows you to communicate between MATLab and Mathematica. – MassDefect Nov 29 '18 at 16:51
• How about you post an example of a slow plot, because Mathematica shouldn't be slower than Matlab for plotting. There are a number of ways you can speed up plots, including within a Dynamic environment. – KraZug Nov 30 '18 at 7:42
• If I compile your function, the table generation time goes from 34s to 6s. – KraZug Nov 30 '18 at 12:12
• f4 = Compile[{{x, _Real}, {y, _Real}, {z, _Real}}, Cos[Pi*x^3] + Cos[Pi*x^3]*Cos[Pi*x^3] + Cos[Pi*z^3] + Sin[x + z] x^2 + y^2 + z^2 + Exp[Cos[Pi*x^3] Cos[Pi*x^3] + Cos[Pi*z^3] + Sin[x + z] x^2 + y^2 + z^2], CompilationTarget -> "C", Parallelization -> True, RuntimeOptions -> "Speed"] gives me 5.7s instead of 34s. – KraZug Nov 30 '18 at 12:20