MATLAB Compiler does not do what you want.
MATLAB Compiler takes your .m
code and encrypts and archives it into a .ctf
(Component Technology File) file. It then produces a thin wrapper (either a .exe
file, or a .dll
library file along with files to enable calling the library from C). You deliver the .ctf
file and the wrapper to your end user along with the freely redistributable MCR (MATLAB Compiler Runtime). It's possible to package either the first two or all three into a single unit for easier distribution.
The end user runs the executable or library, which dearchives and decrypts the .m
code and runs it against the MCR rather than MATLAB. You can think of the MCR as basically a copy of MATLAB, but without the front-end desktop environment.
MATLAB Compiler is intended for the use case that you want to easily share a MATLAB application or algorithm with someone who does not have MATLAB. Because the code is encrypted, you can also use it to protect your intellectual property. But the code remains as .m
code, and executes exactly as it would within MATLAB, including the same speed.
MEX is something different entirely. If you have an algorithm implemented in C code, you can add the 'gateway' routine you mention to it, and compile it with the command mex
into a library that is then callable from MATLAB as if it were a regular MATLAB command or function. MEX functionality is part of regular MATLAB, and doesn't require any add-on products.
There is also another product, MATLAB Coder, that is distinct from MATLAB Compiler.
MATLAB Coder takes .m
code that is in a subset of the MATLAB language, and converts it to C code. The subset is very extensive, but there are a few significant restrictions on the parts of the MATLAB language that are supported. I'm afraid those restrictions include many toolbox functions, including some functionality from Neural Networks Toolbox.
You can then do lots of things with that C code, including using MEX to compile it back into a form usable as a MATLAB command. This can often, though not always, provide a significant speedup over the original .m
code. You can also do other things such as integrate the C code into a wider C project. or deliver it to an embedded device.
The main answer to your question is:
- MATLAB Compiler doesn't do what you need.
- To produce a MEX file file from your
.m
code, either recode it manually into C and then mex it, or use MATLAB Coder to automatically produce C code and then mex it.