Why Compile Matlab?
Compiling your Matlab program will make it run faster. Also, as long as a computer has the same OS and architecture, a compiled Matlab program will be able to run on other computers. The computer you wish to run the compiled program on must also have the proper MCR (Matlab Compiler Runtime) which can be downloaded here. This is beneficial because while Matlab is an expensive, licensed software, the MCR is free.
So there are 2 reasons to compile your Matlab programs:
- It's faster
- They can run on computers that don't have Matlab (but must have MCR)
How to Compile
Compiling a Matlab program is very simple, just type:
mcc -m YourProgram.m
The mcc (Matlab C Compiler) will create a standalone C executable file of your Matlab script. This can be typed either in the terminal or in Matlab itself. Compiling the program will take several seconds to minutes depending upon how large the program is.
You can now run the executable file, and as long as you have the proper MCR installed, the program should run the same as when it ran in Matlab.