Declare uninitialized variables in code generation
copies type, size, and complexity of
X = coder.nullcopy(
does not copy element values. The function preallocates memory for
without incurring the overhead of initializing memory. In code generation, the
coder.nullcopy function declares uninitialized variables. In
coder.nullcopy returns the input such that X is equal
If X is a structure or a class containing variable-sized arrays, then you must assign
the size of each array.
coder.nullcopy does not copy sizes of arrays
or nested arrays from its argument to its result.
Before you use
X in a function or a program,
ensure that the data in
completely initialized. Declaring a variable through
coder.nullcopy without assigning
all the elements of the variable results in
nondeterministic program behavior. For more information, see How to Eliminate Redundant Copies by Defining Uninitialized Variables.
X as a 1-by-5 vector of real doubles
without performing an unnecessary initialization:
function X = foo %#codegen N = 5; X = coder.nullcopy(zeros(1,N)); for i = 1:N if mod(i,2) == 0 X(i) = i; else X(i) = 0; end end
zeros lets you specify the size of
X without initializing each element to zero.
A— Variable to copy
Variable to copy, specified as a scalar, vector, matrix, or multidimensional array.
Complex Number Support: Yes
You cannot use
coder.nullcopy on sparse matrices.
You cannot use
coder.nullcopy with classes that support
overloaded parentheses or require indexing methods to access their data, such as