title: How Do I Prevent MATLAB from Dropping the "complex" Attribute of an Array?
body: <p>The following MATLAB code snippet, which creates two arrays of complex numbers,</p>
  
  <pre><code>x = complex(1:2,0:1);
  y = complex(zeros(1,2),0);
  whos x y
  </code></pre>
  
  <p>prints</p>
  
  <pre><code>  Name      Size            Bytes  Class     Attributes
  
    x         1x2                32  double    complex   
    y         1x2                32  double    complex
  </code></pre>
  
  <p>as expected.  However, after these two additional statements,</p>
  
  <pre><code>y(1) = x(1);
  whos x y
  </code></pre>
  
  <p>the following gets printed:</p>
  
  <pre><code>  Name      Size            Bytes  Class     Attributes
  
    x         1x2                32  double    complex   
    y         1x2                16  double
  </code></pre>
  
  <p>How can one prevent the complex attribute from being dropped?</p>
  
  <p>For the record, Octave does the same.</p>
  
  <p>In practice, <code>x</code> is a function argument whose first entry happens to have a zero imaginary part, and <code>y</code> is the return value that is being preallocated.</p>