Documentation

coder.allowpcode

Package:coder

Control code generation from protectedMATLABfiles

Syntax

coder.allowpcode('plain')

Description

coder.allowpcode('plain')allows you to generate protected MATLAB®code (P-code) that you can then compile into optimized MEX functions or embeddable C/C++ code. This function does not obfuscate the generated MEX functions or embeddable C/C++ code.

With this capability, you can distribute algorithms as protected P-files that provide code generation optimizations, providing intellectual property protection for your source MATLAB code.

Call this function in the top-level function before control-flow statements, such asif,while,switch, and function calls.

MATLAB functions can call P-code. When the.mand每分钟versions of a file exist in the same folder, the P-file takes precedence.

coder.allowpcodeis ignored outside of code generation.

Examples

Generate optimized embeddable code from protected MATLAB code:

  1. Write an functionp_absthat returns the absolute value of its input:

    function out = p_abs(in) %#codegen % The directive %#codegen indicates that the function % is intended for code generation coder.allowpcode('plain'); out = abs(in);

  2. Generate protected P-code. At the MATLAB prompt, enter:

    pcodep_abs
    The P-file,p_abs.p, appears in the current folder.

  3. Generate a MEX function forp_abs.p, using the-argsoption to specify the size, class, and complexity of the input parameter (requires aMATLAB Coder™license). At the MATLAB prompt, enter:

    codegen p_abs -args { int32(0) }
    codegengenerates a MEX function in the current folder.

  4. Generate embeddable C code forp_abs.p(requires aMATLAB Coderlicense). At the MATLAB prompt, enter:

    codegen p_abs -config:lib -args { int32(0) };
    codegengenerates C library code in thecodegen\lib\p_absfolder.

See Also

|

Introduced in R2011a

Was this topic helpful?