Array Layout

Column-major and row-major order for array storage

Array layout refers to the order in which array elements are stored in memory. By default, MATLAB® Coder™ generates code that uses column-major layout. You can also generate code that uses row-major. Row-major layout can improve performance for certain algorithms and ease integration with external code or data that uses row-major. Linear indexing operations always use column-major layout in generated code.

Functions

codegenGenerate C/C++ code from MATLAB code
coder.cevalCall external C/C++ function
coder.columnMajorSpecify column-major array layout for a function or class
coder.isColumnMajorDetermine whether the current function or variable uses column-major layout
coder.isRowMajorDetermine whether the current function or variable uses row-major layout
coder.rowMajorSpecify row-major array layout for a function or class

Classes

coder.CodeConfigConfiguration parameters for C/C++ code generation from MATLAB code
coder.MexCodeConfigConfiguration parameters for MEX function generation from MATLAB code
coder.EmbeddedCodeConfigConfiguration parameters for C/C++ code generation from MATLAB code with Embedded Coder

Topics

Row-Major and Column-Major Array Layouts

Understand how MATLAB stores array elements in memory.

Generate Code That Uses Row-Major Array Layout

Generate C/C++ code with row elements stored contiguously in memory.

Specify Array Layout in Functions and Classes

Combine different array layouts in a single code project.

Code Design for Row-Major Array Layout

Design your code for efficient use of array layout.