pcode *.m
See the pcode function reference page for a description of all syntaxes for generating P-
code files.
Invoking the P-Code File
You invoke the resulting P-code file in the same way you invoke the MATLAB .m source
file from which it was derived. For example, to invoke file myfun.p, type
[out, out2, ...] = myfun(in1, in2, ...);
To invoke script myscript.p, type
myscript;
When you call a P-code file, MATLAB gives it execution precedence over its
corresponding .m source file. This is true even if you happen to change the source code at
some point after generating the P-code file. Remember to remove the .m source file
before distributing your code.
Running Older P-Code Files on Later Versions of MATLAB
P-code files are designed to be independent of the release under which they were created
and the release in which they are used (backward and forward compatibility). New and
deprecated MATLAB features can be a problem, but it is the same problem that would
exist if you used the original MATLAB input file. To fix errors of this kind in a P-code file,
fix the corresponding MATLAB input file and create a new P-code file.
P-code files built using MATLAB Version 7.4 and earlier have a different format than those
built with more recent versions of MATLAB. These older P-code files do not run in
MATLAB 8.6 (R2015b) or later. Rebuild any P-code files that were built with MATLAB 7.4
or earlier using a more recent version of MATLAB, and then redistribute them as
necessary.
Building a Standalone Executable
Another way to protect your source code is to build it into a standalone executable and
distribute the executable, along with any other necessary files, to external customers. You
must have the MATLAB Compiler and a supported C or C++ compiler installed to prepare
files for deployment. The end user, however, does not need MATLAB.
25 Programming Utilities