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.
The size defaults to
-1, which means that the data inherits its size
based on the value of the Scope property:
|Inherits size from the Simulink® signal connected to the associated input port.|
|Inherits size from the Simulink signal connected to the associated output port.|
|Inherits size from the associated Simulink or MATLAB® parameter. See Configure MATLAB Function Block Parameter Data Arguments.|
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
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
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:
For example, consider a MATLAB Function block with data
y that all have the
Scope property set to
k is a scalar and
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.
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.