Generating Code

How to generate code and build standalone libraries and executables

Apps

MATLAB Coder Generate C code or MEX function from MATLAB code

Functions

coder Open MATLAB Coder app
codegen Generate C/C++ code from MATLAB code
coder.allowpcode Control code generation from protected MATLAB files
coder.ceval Call external C/C++ function
coder.cinclude Include header file in generated code
coder.config Create MATLAB Coder code generation configuration objects
coder.cstructname Name structure in generated code
coder.extrinsic Declare extrinsic function or functions
coder.load Load compile-time constants from MAT-file or ASCII file into caller workspace
coder.newtype Create a coder.Type object
coder.nullcopy Declare uninitialized variables
coder.opaque Declare variable in generated code
coder.ref Pass argument by reference as read input or write output
coder.resize Resize a coder.Type object
coder.rref Pass argument by reference as read-only input
coder.target Determine if code generation target is specified target
coder.typeof Convert MATLAB value into its canonical type
coder.varsize Declare variable-size array
coder.wref Pass argument by reference as write-only output

Examples and How To

Set Up a MATLAB Coder Project

Set up a project in the MATLAB® Coder™ app.

C Code Generation Using the MATLAB Coder App

Generate C/C++ code from MATLAB code by using the MATLAB Coder app.

C Code Generation at the Command Line

Generate C/C++ code from MATLAB code by using the codegen command.

Convert MATLAB Coder Project to MATLAB Script

Use project settings to generate code at the command line.

Generate Code for Variable-Size Data

Generate code for data whose size might change at run time.

Generate Code for Enumerations

Generate code from MATLAB code that uses enumerations.

Generate Code for Global Data

Generate C/C++ code from MATLAB code that uses global data

Generate Code for Multiple Entry-Point Functions

Generate a C/C++ library that contains multiple entry-point functions.

Speed Up Compilation by Generating Only Code

Generate C source code without building object code.

Concepts

Code Generation Workflow

Generate C/C++ code from MATLAB code.

C/C++ Code Generation

Generate MEX functions, C/C++ static and dynamic libraries, and C/C++ executable programs.

How MATLAB Coder Partitions Generated Code

Select file partitioning method.

Troubleshooting

Run-time Stack Overflow

Set the value of the maximum stack usage parameter.

Unable to Open a MATLAB Coder Project

Use a backup project file to revert to the format of an earlier release.

Slow Operations in MATLAB Coder App

Disable code generation readiness screening.

Was this topic helpful?