Main Content

Specify Size of MATLAB Function Block Data

You can specify the size of the data in MATLAB Function blocks with the Ports and Data Manager or the Model Explorer. For more information about specifying data, see Define MATLAB Function Block Data. You can specify the data size as a scalar, vector, or matrix.

Inherit Argument Sizes from Simulink

The size defaults to -1, which means that the data inherits its size based on the value of the Scope property:

ScopeDescription
InputInherits size from the Simulink® signal connected to the associated input port.
OutputInherits size from the Simulink signal connected to the associated output port.
ParameterInherits size from the associated Simulink or MATLAB® parameter. See Configure MATLAB Function Block Parameter Data Arguments.

Customize Data Sizes

You can also manually set the size of data to a scalar, vector, or matrix. To specify the data size as a scalar, set Size to 1 or clear the parameter. To specify the data size as a vector or a matrix, enter a row vector in [row column] format. For example, to define a row vector of size 5, set the Size property to [1 5]. To define a column vector of size 6, set the Size property to [6 1]. To define a matrix of size 3-by-3, set the Size property to [3 3].

Note

Prior to R2021b, MATLAB Function blocks output column vectors as one-dimensional data. In R2021b and later, MATLAB Function blocks retain their dimensionality by default. To maintain the old behavior, clear the Interpret output column vectors as one-dimensional data property in the Ports and Data Manager or Model Explorer. Once you clear this property, you can then use a single number in Size to define a column vector. See Interpret output column vectors as one-dimensional data.

You can also set the Size property with an expression, as long as the expression outputs a value that follows the guidelines above. The expressions can include:

  • Numeric constants

  • Arithmetic operators, restricted to +, -, *, and /

  • Names of data with the Scope property set to Parameter

  • Calls to the MATLAB functions min, max, and size

For example, consider a MATLAB Function block with data k, x, and y that all have the Scope property set to Parameter. Here, k is a scalar and x and y are matrices. If you create new data for the block, you can define the Size property with any of the following expressions:

k+1
size(x)
min(size(y))

Expressions that do not return scalars or a 2-by-1 array produce an error at model compilation.

Simulation and Size Matching

After you build the model, the CompiledSize column in the Model Explorer and Compiled Size column in the Ports and Data Manager display the actual data size used in the simulation. If the value of the Size property is not -1 and does not match the actual size, a mismatch error occurs during model compilation.

See Also

Related Topics