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.
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 1x:n
or :nx1
(one
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.
When the function selects the working dimension automatically,
it bases the selection on the upper bounds for the dimension sizes.
In the case of the sum
function, sum(X)
selects
its working dimension automatically, while sum(X, dim)
uses dim
as
the explicit working dimension.
For example, if X
is a variable-size matrix
with dimensions 1x:3x:5
, sum(x)
behaves
like sum(X,2)
in generated code. In MATLAB®,
it behaves like sum(X,2)
provided size(X,2)
is
not 1. In MATLAB, when size(X,2)
is 1, sum(X)
behaves
like sum(X,3)
. Consequently, you get a run-time
error if an automatically selected working dimension assumes a length
of 1 at run time.
To avoid the issue, specify the intended working dimension explicitly as a constant value.
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.
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 — Alphabetical List.
Function | Restrictions for Variable-Size Data |
---|---|
all |
|
any |
|
bsxfun |
|
cat |
|
conv |
|
cov |
|
cross |
|
deconv |
|
detrend |
|
diag | |
diff |
|
fft | |
filter |
|
hist |
|
histc | |
ifft | |
ind2sub |
|
interp1 |
|
ipermute |
|
issorted |
|
magic |
|
max | |
mean |
|
median |
|
min | |
mode |
|
mtimes |
|
nchoosek |
|
permute |
|
planerot |
|
poly | |
polyfit |
|
prod |
|
rand |
|
randi |
|
randn |
|
reshape |
|
roots | |
shiftdim |
|
std |
|
sub2ind |
|
sum |
|
trapz |
|
typecast |
|
var |
|