VariableSizing Restrictions for Code Generation of Toolbox Functions
Common Restrictions
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 VariableSize Data.
Variablelength vector restriction
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.
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 runtime error checks are enabled, an error can occur.
For example, suppose that X
is a variablesize
matrix with dimensions 1x:3x:5
. In the generated
code, sum(X)
behaves like sum(X,2)
.
In MATLAB, sum(X)
behaves like sum(X,2)
unless size(X,2)
is
1. In MATLAB, when size(X,2)
is 1, sum(X)
behaves
like sum(X,3)
.
To avoid this issue, specify the intended working dimension
explicitly as a constant value. For example, sum(X,2)
.
Arraytovector restriction
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.
Arraytoscalar restriction
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.
Toolbox Functions with Restrictions for VariableSize Data
The following table list functions that have code generation restrictions for variablesize 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 VariableSize Data 

all 

any 

cat 

conv 

cov 

cross 

deconv 

detrend 

diag 

diff 

fft 

filter 

hist 

histc 

ifft 

ind2sub 

interp1 

interpft 

ipermute 

issorted 

magic 

max 

maxk 

mean 

median 

min 

mink 

mode 

mtimes  Consider the multiplication 
nchoosek 

permute 

planerot 

poly 

polyfit 

prod 

rand 

randi 

randn 

reshape 

roots 

shiftdim 

sort 

std 

sub2ind 

sum 

trapz 

typecast 

var 

vecnorm 
