Documentation

pcode

Create protected function file

Syntax

pcode(fun)
pcode(fun1,...,funN)
pcode(fun,'-inplace')

Description

pcode(fun)obfuscates the code in有趣的.m并生成一个文件有趣的每分钟, known as a P-file. If有趣的is a folder, then all the script or function files in that folder are obfuscated in P-files. MATLAB®creates the P-files in the current folder. The original.mfile or folder can be anywhere on the search path.

pcode(fun1,...,funN)createsNP-files from the listed files. If any inputs are folders, then MATLAB creates a P-file for every.mfile the folders contain.

pcode(fun,'-inplace')creates P-files in the same folder as the script or function files.

Note

  • Thepcode有趣的ctionobfuscatesyour code files, it does notencrypt他们. While the content in a每分钟file is difficult to understand, it should not be considered secure. It is not recommended that you P-code files to protect your intellectual property.

  • Thepcode有趣的ction does not support live scripts or live functions (.mlx).

Input Arguments

有趣的

MATLAB file or directory containing MATLAB files. If有趣的resides within a package and/or class folder, thenpcodecreates the same package and/or class structure to house the resulting P-files.

An input argument with no file extension and that is not a folder must be a function in the MATLAB path or in the current folder.

When using wild cards*,pcodeignores all files with extensions other than.m.

Examples

collapse all

Convert selected files from thesparfunfolder into P-files.

Create a temporary folder and define an existing path to.mfiles.

tmp = tempname; mkdir(tmp) cd(tmp) fun = fullfile(matlabroot,'toolbox','matlab','sparfun','spr*.m');

Create the P-files.

pcode(fun) dir(tmp)
. .. sprand.p sprandn.p sprandsym.p sprank.p

The temporary folder now contains encoded P-files.

Generate P-files from input files that are part of a package and/or class. This example uses an existing MATLAB example class.

Define有趣的classas an existing a class folder that contains.mfiles.

有趣的class = fullfile(docroot,'techdoc','matlab_oop',...'examples','@BankAccount') dir(funclass)
有趣的class = C:\Program Files\MATLAB\R2013a\help\techdoc\matlab_oop\examples\@BankAccount . .. BankAccount.m

Create a temporary folder. This folder has no package or class structure at this time.

tmp = tempname; mkdir(tmp); cd(tmp); dir(tmp)
. ..

Create a P-file for every.mfile in the path有趣的class. Because the input files are part of a package and/or class, MATLAB creates a folder structure so that the output file belongs to the same package and/or class.

pcode(funclass) dir(tmp)
. .. @BankAccount

You see that the P-file resides in the same folder structure.

dir('@BankAccount')
. .. BankAccount.p

Generate P-files in the same folder as the input files using the optioninplace

Copy several MATLAB files to a temporary folder.

有趣的= fullfile(matlabroot,'toolbox','matlab','sparfun','spr*.m'); tmp = tempname; mkdir(tmp); copyfile(fun,tmp) dir(tmp)
. .. sprand.m sprandn.m sprandsym.m sprank.m

Create P-files in the same folder as the original.mfiles.

pcode(tmp,'-inplace') dir(tmp)
. sprand.m sprandn.m sprandsym.m sprank.m .. sprand.p sprandn.p sprandsym.p sprank.p

提示

  • Thepcodealgorithm was redesigned in MATLAB 7.5 (Release R2007b). If your P-file was generated prior to MATLAB 7.5, it will not run in MATLAB 8.6 (Release R2015b) or later. Files generated in 7.5, or later versions, cannot run in MATLAB 7.4 or earlier.

  • When obfuscating all files in a folder,pcodedoes not obfuscate any files within subfolders.

  • A P-file takes precedence over the corresponding MATLAB code file (.m) for execution, even after modifications to the code file.

  • MATLAB does not display any of the help comments that might be in the original MATLAB code file (.m).

Introduced before R2006a

Was this topic helpful?