coder.ignoreSize
Prevent code generator from creating function specializations for constant-size expressions
Syntax
Description
coder.ignoreSize(
declares that the code generator must not use the constant size of an expression to create function specializations.expression
)
Examples
Duplicate Functions Generated for Multiple Input Sizes
If your MATLAB®code calls a function multiple times and passes inputs of different sizes, the code generator can create function specializations for each size. To avoid this issue, usecoder.ignoreSize
on the function input. For example, this code usescoder.ignoreSize
to avoid creating multiple copies of the functionindexOf
:
function[out1, out2] = test1(in) a = 1:10; b = 2:40;% Without coder.ignoreSize duplicate functions are generatedout1 = indexOf(coder.ignoreSize(a), in); out2 = indexOf(coder.ignoreSize(b), in);endfunctionindex = indexOf(array, value) coder.inline('never');fori = 1:numel(array)ifarray(i) == value index = i;returnendendindex = -1;returnend
生成code, enter:
codegentest1-config:lib-report-args{1}
Input Arguments
More About
Tips
If you assign an expression to a variable and declare the variable as variable-size by using
coder.varsize
, this declaration has the same effect as usingcoder.ignoreSize
on the expression.