coder.isColumnMajor - Determine whether the current function or variable uses column-major

        layout - MATLAB ([original](http://www.mathworks.com/access/helpdesk/help/coder/ref/coder.iscolumnmajor.html)) ([raw](?raw))

Main Content

Determine whether the current function or variable uses column-major layout

Syntax

Description

coder.isColumnMajor resolves as true in the generated code if the current function uses column-major array layout. Use the function as the expression in control flow (if, else,switch) statements.

example

coder.isColumnMajor([arg](#d126e17275)) resolves as true if the current variable uses column-major array layout.

example

Examples

collapse all

Query Array Layout of a Function

To query the array layout of a function at compile time, usecoder.isColumnMajor orcoder.isRowMajor. This query can be useful for specializing your generated code when it involves row-major and column-major functions. For example, consider this function:

function S = addMatrixRouted(A,B) if coder.isRowMajor %execute this code if row major S = addMatrix_OptimizedForRowMajor(A,B); elseif coder.isColumnMajor %execute this code if column major S = addMatrix_OptimizedForColumnMajor(A,B); end

The function addMatrixRouted behaves differently depending on whether it uses row-major layout or column-major layout. The layout that the function uses, for example, can depend on whether it is called from a function that contains coder.rowMajor orcoder.columnMajor. WhenaddMatrixRouted uses row-major layout, it calls theaddMatrix_OptimizedForRowMajor function, which has efficient memory access for row-major data. When the function uses column-major layout, it calls a version of the addMatrix function optimized for column-major data.

By using the query functions, the generated code foraddMatrixRouted provides efficient memory access for either choice of array layout.

Query Array Layout of a Variable

Consider the function bar:

function bar coder.columnMajor; x = magic(3); if coder.isColumnMajor(x) fprintf('This will always be displayed in generated code.\n'); else fprintf('This will never be displayed in generated code.\n'); end end

Generate code:

To run the MEX function, enter:

Input Arguments

collapse all

arg — Variable name

array variable

Variable to query for array layout.

Example: coder.isColumnMajor(x);

Limitations

Tips

Extended Capabilities

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation

Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

HDL Code Generation

Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced in R2018a