title: Matlab: Convert superclass to subclass object
body: <p>I want to create a subclass, <code>ess</code> say, to the built-in <code>ss</code> class. I'd like to be able to convert an existing <code>ss</code> object to an <code>ess</code> object and at the same time add the missing properties, e.g. <code>w</code>, by something like this</p>
  
  <pre><code>sys=ss(a,b,c,d);
  esys=ess(sys,w);
  </code></pre>
  
  <p>but I can't figure out how to setup the constructor correctly. What is the best way to achieve this? My code currently looks like this</p>
  
  <pre><code>classdef ess &lt; ss
      properties
          w
      end
      methods
          function obj = ess(varargin)
              if nargin&gt;0 &amp;&amp; isa(varargin{1},'StateSpaceModel')
                  super_args{1} = sys;
              else
                  super_args = varargin;
              end
              obj = obj@ss(super_args{:});
          end
      end 
  end
  </code></pre>
  
  <p>But this does not work as I get the following error:</p>
  
  <pre><code> &gt;&gt; ess(ss(a,b,c,d))
   ??? When constructing an instance of class 'ess', the constructor must preserve
   the class of the returned object.
  </code></pre>
  
  <p>Of course I could copy all the object properties by hand but it seems to me that there should be some better way.</p>