Compile Matlab code to run on any PC

You can compile Matlab code to an executable, so that Matlab isn’t needed to run the .m file–but the free Matlab Compiler Runtime is needed on the non-Matlab PC. 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.

  • Matlab Compiler does NOT in general speedup your Matlab code execution.

Configure PCs

  1. compiling PC: ensure Matlab Compiler is installed:

    1. running PC: Install Matlab Compiler Runtime. The MCR must match the Matlab version of the compiling Matlab.


    1. create test program by saving into a file mymcc.m
    function Y = mymcc()
    X = 0:0.01:2*3.14;
    Y = sin(X);
    title('Test of MCR')
    disp('I ran an MCR program!')
  2. compile .m file in Matlab:

    mcc -m -v mymcc.m
    1. Run compiled Matlab program without Matlab
    ./ mymcc

    which displays

    I ran an MCR program!

    along with a typical Matlab plot window showing a sine wave.

  3. Close the plot window to end the execution of your program.


The Matlab Compiler allows you to compile your existing .m Matlab script to run as an executable on another PC without Matlab.


See the readme.txt created with the mcc command above.