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

NameTypeRequiredDefaultDescription
itemStringScalarYesMATLAB source file, source name, folder, or wildcard pattern to encode.
versionStringScalarNo-R2007bObfuscation compatibility selector, either -R2007b or -R2022a.
item1StringScalarYesFirst MATLAB source file, source name, folder, or wildcard pattern.
itemNStringScalarVariadicAdditional source files, source names, folders, or wildcard patterns.
inplaceStringScalarNoUse -inplace to write each P-code file beside its source file.

Errors

IdentifierWhenMessage
RunMat:pcode:NotEnoughInputsNo 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:InvalidArgumentAn argument is not a character row, string scalar, or scalar string array.pcode: arguments must be character vectors or string scalars

How pcode works

  • pcode(item) accepts a source name, .m path, folder, or wildcard pattern and writes .p files in the current folder.
  • When item names a folder, RunMat encodes the .m files directly in that folder. Folder processing is nonrecursive, matching the common MATLAB pcode(folder) behavior.
  • pcode(item, '-inplace') writes each generated .p beside its source .m file.
  • pcode(item, '-R2007b') and pcode(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 .m files and ignore non-source files.
  • When source files live in package or class folders, non-inplace output preserves the trailing +package and @class folder structure under the current folder.
  • pcode has no outputs. Requesting output arguments raises RunMat:pcode:TooManyOutputs.
  • Live scripts (.mlx) and non-.m source files are not supported and raise RunMat: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 worker

Write P-code beside the source file

pcode src/worker.m -inplace

Encode multiple files with the newer RunMat obfuscation label

pcode src/*.m helpers/*.m -R2022a

Using 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how pcode is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.