title: How do I make complex int16 numbers in octave?
body: <p>In Matlab (my version happens to be R2010b) one can convert a complex double into a complex int16 type as so:</p>
  
  <pre><code>&gt;&gt; a = 8.3+4.9j;
  &gt;&gt; ai16 = int16(a)
  ai16 = 
      8 + 5i
  &gt;&gt; whos ai16
  Name       Size       Bytes       Class     Attributes
  ai16       1x1            4       int16     complex
  </code></pre>
  
  <p>i.e. ai16 is a complex int16 type (equivalent to C++ complex&lt; short > for example).</p>
  
  <p>Octave (ver 4.0.0) does not like this one bit:</p>
  
  <pre><code>&gt;&gt; ai16 = int16(a)
  error: invalid conversion from complex scalar to int16 scalar
  </code></pre>
  
  <p>I am trying to port some legacy Matlab code to Octave.  Does anyone have a suggestion on how to get around this in a painless way?  I thought of this:</p>
  
  <pre><code>ai16.real = int16(real(a));
  ai16.imag = int16(imag(a));
  </code></pre>
  
  <p>but that would propagate a lot of pain through out the code base.  There are many arrays that have been converted from complex double to complex int16. And these arrays are used in many computations.</p>