Code generation from MATLAB® code supports many major language features including:
n-dimensional arrays (see Array Size Restrictions for Code Generation)
matrix operations, including deletion of rows and columns
variable-size data (see Code Generation for Variable-Size Arrays)
subscripting (see Incompatibility with MATLAB in Matrix Indexing Operations for Code Generation)
complex numbers (see Code Generation for Complex Data)
numeric classes (see Supported Variable Types)
double-precision, single-precision, and integer math
enumerations (see Code Generation for Enumerations)
fixed-point arithmetic (see Code Acceleration and Code Generation from MATLAB)
program control statements if
, switch
, for
, while
, and break
arithmetic, relational, and logical operators
local functions
persistent variables
global variables
structures (see Structure Definition for Code Generation)
cell arrays (see Cell Arrays)
tables (see Code Generation for Tables)
timetables (see Code Generation for Timetables)
characters (see Encoding of Characters in Code Generation)
string scalars (see Code Generation for Strings)
categorical
arrays (see Code Generation for Categorical Arrays)
datetime
arrays (see Code Generation for Datetime Arrays)
duration
arrays (see Code Generation for Duration Arrays)
sparse matrices (see Code Generation for Sparse Matrices)
function handles (see Function Handle Limitations for Code Generation)
anonymous functions (see Code Generation for Anonymous Functions)
recursive functions (see Code Generation for Recursive Functions)
nested functions (see Code Generation for Nested Functions)
variable length input and output argument lists (see Code Generation for Variable Length Argument Lists)
subset of MATLAB toolbox functions (see Functions and Objects Supported for C/C++ Code Generation)
subset of functions and System objects in several toolboxes (see Functions and Objects Supported for C/C++ Code Generation)
MATLAB classes (see MATLAB Classes Definition for Code Generation)
function calls (see Resolution of Function Calls for Code Generation)
Code generation from MATLAB does not support the following frequently used MATLAB features (this list is not exhaustive):
scripts
implicit expansion
Code generation does not support implicit expansion of arrays with
compatible sizes during execution of element-wise operations or
functions. If your MATLAB code relies on implicit expansion, code generation
results in a size-mismatch error. For fixed-size arrays, the error
occurs at compile time. For variable-size arrays, the error occurs
at run time. For more information about implicit expansion, see
Compatible Array Sizes for Basic Operations. For code
generation, to achieve implicit expansion, use bsxfun
.
GPU arrays
MATLAB Coder™ does not support GPU arrays. However, if you have GPU Coder™, you can generate CUDA® MEX code that takes GPU array inputs.
calendarDuration
arrays
Java®
Map containers
time series objects
try
/catch
statements
import
statements
Function argument validation