Main Content

Data Definition Basics

Define data, variables, and functions for code generation

MATLAB® variables can change their properties at run time. The same variable can hold a value of any class, size, or complexity. Statically typed languages such as C/C++ must determine variable types at compile time. Follow the described guidelines to allow the code generator to determine the types of variables when generating code. Code generation allows reassignment of a variable to a value of different class, size, and property. Code generation supports special MATLAB data types such as complex data, half-precision floating-point types, and sparse matrices.

Functions

halfConstruct half-precision numeric object

Topics

Definition Basics

Data Definition for Code Generation

Define data in MATLAB code intended for code generation.

Variables Definition for Code Generation

Define the class, size, and complexity of variables in MATLAB source code before using them.

Best Practices for Defining Variables for C/C++ Code Generation

Follow guidelines for defining variables in MATLAB code intended for code generation.

Eliminate Redundant Copies of Variables in Generated Code

Use coder.nullcopy to indicate that the code generator can allocate memory without initializing it.

Variable Properties

Reassignment of Variable Properties

Reassign a variable with a value of different class, size, or complexity.

Reuse the Same Variable with Different Properties

Reuse a variable with different properties when the code generator can determine the properties of each occurrence of the variable.

Data Definition for Special Data Types

Code Generation for Complex Data

Use complex data in MATLAB code intended for code generation.

Code Generation for Sparse Matrices

Use sparse matrices in MATLAB code intended for code generation.

Code Generation for Constants in Structures and Arrays

Sometimes the code generator does not recognize constant structure fields or array elements.

Array Size Restrictions for Code Generation

The code generator and the target hardware constrain the maximum number of elements of an array.

Half Precision Code Generation Support

C/C++ and GPU code generation support for functions that support half-precision inputs.

Featured Examples