pcode — Generate RunMat-executable content-obscured P-code files from MATLAB source.
pcode reads MATLAB .m source files and writes RunMat-generated .p files that obscure the source text while remaining executable by RunMat. RunMat does not implement MathWorks' proprietary P-code file format; non-RunMat .p files are rejected with a deterministic invalid-P-code error.
Syntax
pcode(item)
pcode(item, version)
pcode(item1, item2, ..., itemN, "-inplace")Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
item | StringScalar | Yes | — | MATLAB source file, source name, folder, or wildcard pattern to encode. |
version | StringScalar | No | -R2007b | Obfuscation compatibility selector, either -R2007b or -R2022a. |
item1 | StringScalar | Yes | — | First MATLAB source file, source name, folder, or wildcard pattern. |
itemN | StringScalar | Variadic | — | Additional source files, source names, folders, or wildcard patterns. |
inplace | StringScalar | No | — | Use -inplace to write each P-code file beside its source file. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:pcode:NotEnoughInputs | No source item is provided. | pcode: not enough input arguments |
RunMat:pcode:TooManyOutputs | `pcode` is called with requested output arguments. | pcode: too many output arguments |
RunMat:pcode:InvalidArgument | An argument is not a character row, string scalar, or scalar string array. | pcode: arguments must be character vectors or string scalars |
RunMat:pcode:EmptyItem | A source item is empty. | pcode: source item must not be empty |
RunMat:pcode:InvalidOption | An option is not -inplace, -R2007b, or -R2022a. | pcode: invalid option |
RunMat:pcode:PathResolveFailed | RunMat cannot resolve a source item or destination path. | pcode: failed to resolve path |
RunMat:pcode:FileNotFound | No MATLAB `.m` source file matches the item. | pcode: source file not found |
RunMat:pcode:UnsupportedExtension | The source item names an unsupported file type, including `.mlx` live scripts. | pcode: only MATLAB .m source files are supported |
RunMat:pcode:FileReadFailed | A source file cannot be read as text. | pcode: failed to read source file |
RunMat:pcode:FileWriteFailed | The destination `.p` file cannot be written. | pcode: failed to write P-code file |
RunMat:pcode:InvalidPcode | A `.p` file is not a RunMat-generated P-code container or fails integrity checks. | pcode: invalid or unsupported P-code file |
How pcode works
pcode(item)accepts a source name,.mpath, folder, or wildcard pattern and writes.pfiles in the current folder.- When
itemnames a folder, RunMat encodes the.mfiles directly in that folder. Folder processing is nonrecursive, matching the common MATLABpcode(folder)behavior. pcode(item, '-inplace')writes each generated.pbeside its source.mfile.pcode(item, '-R2007b')andpcode(item, '-R2022a')select RunMat's compatibility-labeled obfuscation algorithms. The default is-R2007b.- Multiple items are accepted in one call, including command syntax such as
pcode src/*.m -R2022a -inplace. - Wildcard items only encode matching
.mfiles and ignore non-source files. - When source files live in package or class folders, non-inplace output preserves the trailing
+packageand@classfolder structure under the current folder. pcodehas no outputs. Requesting output arguments raisesRunMat:pcode:TooManyOutputs.- Live scripts (
.mlx) and non-.msource files are not supported and raiseRunMat:pcode:UnsupportedExtension.
Does RunMat run pcode on the GPU?
pcode is a host filesystem/source-packaging operation and is not eligible for provider-native execution or fusion.
Examples
Create P-code in the current folder
pcode worker
run workerWrite P-code beside the source file
pcode src/worker.m -inplaceEncode multiple files with the newer RunMat obfuscation label
pcode src/*.m helpers/*.m -R2022aUsing pcode with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how pcode changes the result.
Run a small pcode example, explain the result, then change one input and compare the output.
FAQ
Can RunMat execute .p files generated by MATLAB?⌄
No. MATLAB P-code is proprietary and undocumented. RunMat executes .p files generated by RunMat and reports an invalid/unsupported P-code error for other .p contents.
Does P-code provide cryptographic secrecy?⌄
No. RunMat's P-code is content-obscured source packaging for compatibility workflows, not a cryptographic protection or licensing boundary.
Does run prefer P-code over source?⌄
Yes. For bare script names and source-path inputs without an extension, RunMat resolves .p before .m and decodes RunMat-generated P-code before execution.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite
Tabular
arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines
Import
Json
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how pcode is executed, line by line, in Rust.
- View the source for pcode in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.