X = coder.nullcopy(A)
X = coder.nullcopy(A)
copies
type, size, and complexity of A
to X
,
but does not copy element values. Preallocates memory for X
without
incurring the overhead of initializing memory.
coder.nullcopy
does not support MATLAB® classes
as inputs.
Use this function with caution. See How to Eliminate Redundant Copies by Defining Uninitialized Variables.
The following example shows how to declare variable X
as
a 1-by-5 vector of real doubles without performing an unnecessary
initialization:
function X = foo 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
Using coder.nullcopy
with zeros
lets you specify the size of vector X
without
initializing each element to zero.