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 Variable Sizing Restrictions.
Inputs to the library function must be variablelength vectors
or fixedsize vectors. A variablelength vector is a variablesize
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 variablesize 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 runtime
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 variablesize array that is not a variablelength vector assumes the shape of a vector at run time. To avoid the issue, specify the input explicitly as a variablelength vector instead of a variablesize array.
The function issues an error if a variablesize array assumes a scalar value at run time. To avoid this issue, specify scalars as fixed size.
The following restrictions apply to specific toolbox functions, but only for code generation.
Function  Restrictions with VariableSize 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 
