# 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.

• 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
• "ToMatlab is not an option for me". Did you look at what that package does? While the question is not very clearly phrased, as far as I can tell it does exactly what you want. It converts expressions from Mathematica syntax to MATLAB syntax. – Szabolcs Nov 30 '18 at 10:29
• 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
• @KraZug Parallelization is redudant here, it won't have any effect without RuntimeAttributes -> {Listable}. – xzczd Dec 1 '18 at 8:42