Compile Matlab .m code executable

Matlab Compiler compiles existing .m Matlab script to run as an executable on another PC without Matlab. Matlab Compiler Runtime MCR is used on computers that don’t have Matlab to run the compiled Matlab code.

Caveats:

  • Matlab Compiler does not in general speedup Matlab code execution
  • in general, compiled binaries might be disassembled to reverse-engineer the underlying code
  • MCR version on each computer running the executable must match the Matlab version of the compiling Matlab, and the compiling computer must have the same operating system as the MCR running computers.

Compiling computer: ensure Matlab Compiler is installed:

assert(license('test', 'compiler') == 1)

Example program “mymcc.m”:

function Y = mymcc()

X = 0:0.01:2*3.14;
Y = sin(X);
plot(X,Y)
title('Test of MCR')
xlabel('x')
ylabel('y')
disp('I ran an MCR program!')

end

Compile “.m” file in Matlab:

mcc -m -v mymcc.m

Run compiled Matlab program:

./run_mymcc.sh mymcc

I ran an MCR program!

and show a Matlab plot window showing a sine wave. Close the plot window to end the execution of your program.


Notes:

Reference

GNU Octave does not currently have the ability to compile “.m” files. Octave mkoctfile is to distribute C / C++ code that calls Octave functions–and ABI-compatible Octave must be installed on the user computers