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

**compiling PC**: ensure Matlab Compiler is installed:`assert(license('test','compiler')==1)`

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

## Example

create test program by saving into a file

`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 without Matlab

`./run_mymcc.sh mymcc`

which displays

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.

## Notes

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

### Troubleshooting

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