Create a Content-Obscured File with P-Code
A P-code file behaves the same as the MATLAB® source from which it was produced. The P-code file also runs at the same speed as the source file. P-code files are purposely obfuscated.
Note
Security Considerations: The
pcode
function produces MATLAB program files in a proprietary, obfuscated code format. Consider
combining multiple approaches to protect sensitive code or data. For more
information, see Security Considerations to Protect Your Source Code.
Create P-Code Files
To generate a P-code file, enter the following command in the MATLAB Command Window:
pcode file1 file2, ...
The command produces the files file1.p
,
file2.p
, and so on. To convert all .m
source files residing in your current folder to P-code files, use the
command:
pcode *.m
See the pcode
function reference page for a
description of all syntaxes for generating P-code files.
Invoke P-Code Files
You can invoke the resulting P-code files in the same way you invoke the
MATLAB
.m
source files from which they were produced. For example, to
invoke file myfun.p
, type:
[out1,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 change the source
code at generating the P-code file. Remember to remove the .m
source file before distributing your code.
Run Older P-Code Files on Later Versions of MATLAB
P-code files are designed to be independent of the release in which they were created and the release in which they are used (backward and forward compatibility). New and deprecated MATLAB features can cause errors, but these errors would also appear if you used the original MATLAB source file. To fix errors of this kind in a P-code file, fix the corresponding MATLAB source file and create a new P-code file.
P-code files built using MATLAB Version 7.4 (R2007a) 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 V8.6 (R2015b) or later. Rebuild any P-code files that were built with MATLAB V7.4 or earlier using a more recent version of MATLAB, and then redistribute them as necessary.