Main Content

coder.dataAlignment

Specify data alignment for global or entry-point/exported function input and output arguments

Description

example

coder.dataAlignment('varName',align_value) specifies data alignment in MATLAB® code for the variable (varName), which is imported data or global (exported) data. The code generator aligns the imported or exported data to the alignment boundary (align_value).

Examples

collapse all

An example function that specifies data alignment for imported data.

function y = importedDataExampleFun(x1,x2)

coder.dataAlignment('x1',16);	  % Specifies information
coder.dataAlignment('x2',16);    % Specifies information
coder.dataAlignment('y',16);     % Specifies information

y = x1 + x2;

end

An example function that specifies data alignment for exported data.

function a = exportedDataExampleFun(b)

global z;
coder.dataAlignment('z',8);

a = b + z;

end

Input Arguments

collapse all

The varName is a character array of the variable name that requires alignment information specification.

The align_value is an integer number which should be a power of 2, from 2 through 128. This number specifies the power-of-2 byte alignment boundary.

Limitations

Limitations on variables supported by coder.dataAlignment directive:

  • Only use coder.dataAlignment to specify alignment information for function inputs, outputs, and global variables.

  • coder.dataAlignment supports only matrix types, including matrix of complex types.

  • For exported custom storage classes (CSCs), coder.dataAlignment supports only ExportedGlobal. You can specify alignment information for any imported CSCs.

  • The code generator ignores coder.dataAlignment for non-ERT or non-ERT derived system target files.

  • Global variables tagged using the coder.dataAlignment directive from within a MATLAB function block are ignored. Set the alignment value on the corresponding Data Store Memory.

  • The coder.dataAlignment function generates an error if a code replacement library is not specified.

Introduced in R2017a