coder.columnMajor - Specify column-major array layout for a function or class - MATLAB (original) (raw)

Main Content

Specify column-major array layout for a function or class

Syntax

Description

coder.columnMajor specifies column-major array layout for the data used by the current function in generated code. When placed in a class constructor, coder.columnMajor specifies column-major layout for data used by the class.

Note

By default, code generation uses column-major array layout.

example

Examples

collapse all

Specify column-major array layout for a function by insertingcoder.columnMajor into the function body.

Suppose that myFunction is the top-level function of your code. Your application requires you to perform matrix addition with column-major array layout and matrix multiplication with row-major layout.

function S = myFunction(A,B) %#codegen % check to make sure inputs are valid if size(A,1) ~= size(B,1) || size(A,2) ~= size(B,2) disp('Matrices must be same size.') return; end % make both matrices symmetric B = BB'; A = AA'; % add matrices S = addMatrix(A,B); end

Write a function for matrix addition called addMatrix. Specify column-major for addMatrix by usingcoder.columnMajor.

function S = addMatrix(A,B) %#codegen S = zeros(size(A)); coder.columnMajor; % specify column-major array layout S = A + B; end

Generate code for myFunction. Use thecodegen command.

codegen myFunction -args {ones(10,20),ones(10,20)} -config:lib -launchreport -rowmajor

Because of the codegen -rowmajor option, the matrix multiplication in myFunction uses row-major layout. However, the generated code for addMatrix uses column-major array layout due to the coder.columnMajor call.

Tips

Extended Capabilities

Version History

Introduced in R2018a