Variable-Sizing Restrictions for Code Generation of Toolbox Functions
The following common restrictions apply to multiple toolbox functions, but only for code generation. To determine which of these restrictions apply to specific library functions, see the table in Toolbox Functions with Restrictions for Variable-Size Data.
Variable-length vector restriction
Inputs to the library function must be variable-length vectors or
fixed-size vectors. A variable-length vector is a variable-size array that
has the shape
dimension is variable sized and the other is fixed at size 1). Other shapes
are not permitted, even if they are vectors at run time.
Automatic dimension restriction
This restriction applies to functions that take the working dimension (the dimension along which to operate) as input. In MATLAB® and in code generation, if you do not supply the working dimension, the function selects it. In MATLAB, the function selects the first dimension whose size does not equal 1. For code generation, the function selects the first dimension that has a variable size or that has a fixed size that does not equal 1. If the working dimension has a variable size and it becomes 1 at run time, then the working dimension is different from the working dimension in MATLAB. Therefore, when run-time error checks are enabled, an error can occur.
For example, suppose that
X is a variable-size
matrix with dimensions
1x:3x:5. In the generated
sum(X) behaves like
sum(X) behaves like
1. In MATLAB, when
size(X,2) is 1,
To avoid this issue, specify the intended working dimension
explicitly as a constant value. For example,
The function issues an error when a variable-size array that is not a variable-length vector assumes the shape of a vector at run time. To avoid the issue, specify the input explicitly as a variable-length vector instead of a variable-size array.
The function issues an error if a variable-size array assumes a scalar value at run time. To avoid this issue, specify scalars as fixed size.
Toolbox Functions with Restrictions for Variable-Size Data
The following table list functions that have code generation restrictions for variable-size data. For additional restrictions for these functions, and restrictions for all functions and objects supported for code generation, see Functions and Objects Supported for C/C++ Code Generation (MATLAB Coder).
|Function||Restrictions for Variable-Size Data|
Consider the multiplication