This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Package: coder

Declare uninitialized variables


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 With Caution

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;
      X(i) = 0;

Using coder.nullcopy with zeros lets you specify the size of vector X without initializing each element to zero.

Introduced in R2011a

Was this topic helpful?