Matlab “.m” code can be compiled to an executable so that Matlab isn’t needed to run compiled Matlab code. The free Matlab Compiler Runtime is needed on the non-Matlab computer to run the binary executable from Matlab Compiler.
Matlab Compiler does not in general speedup your Matlab code execution. Keep in mind that any executable binary generated by any means from any coding language can be disassembled to reverse-engineer the underlying code, so distributing an executable instead of “.m” code does not completely secure IP from theft. Matlab Compiler is said to use AES encryption but since the method is non-public, there could be unknown vulnerabilities.
The Matlab Compiler Runtime (MCR) version on each computer running the executable must match the Matlab version of the compiling Matlab. This information must be shared with executable users. The compiling computer must be on the same operating system as the MCR running computers.
Compiling computer: ensure Matlab Compiler is installed:
assert(license('test', 'compiler') == 1)
non-Matlab computers: Install MCR
create test program by saving into a file
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
.mfile in Matlab:
mcc -m -v mymcc.m
Run compiled Matlab program without Matlab
I ran an MCR program!
along with a typical Matlab plot window showing a sine wave.
Close the plot window to end the execution of your program.
Matlab Compiler compiles existing .m Matlab script to run as an executable on another PC without Matlab.
GNU Octave does not currently have the ability to compile
.m files as Matlab does.
Another way to share
.m code with non-Matlab users is to have them install free GNU Octave, which runs almost all Matlab
.m code that doesn’t use obscure specialized proprietary Matlab toolboxes.
See the readme.txt created with the mcc command above.