title: Matlab OOP: Create a handle class that (inherits from) is also a double?
body: <p>I would like to create a class that inherits (and acts) as a double but is also a handle. For example:</p>
  
  <pre><code>a     = myHandleDoubleClass();   % Instance of my handle double.
  a.val = 1;                       % Set value of a to 1.
  b     = a                        % Assign b to the value of a
                                   % but, b is a double, not object
  &gt;&gt; b
  
  b = 
      1
  </code></pre>
  
  <p>now if I change the value of a (for example set <code>a.val = 2</code>) then <code>b</code> should also change so that it has the same value (or more correctly both a and b are in effect pointers to the same value). </p>
  
  <p>Is this possible in Matlab somehow?</p>
  
  <p>EDIT: To further clarify, these handle objects should later on be used as normal doubles and need to act as such for access operations (for example <code>b=a</code>, <code>b=a(ind)</code> etc. without having to explicitly access the value property (its ok to use the property field to set the value, <code>a.val = 1</code>). The purpose is to have an double object that is used in many places (other objects, including patches) and you only have to change the value in one place (and all other references update automatically due to the handle property).</p>
  
  <p>EXAMPLE:</p>
  
  <p>One application would be something like this, crate a patch with vertices of my double class</p>
  
  <pre><code>f = [1 2 3];
  v = myDoubles();
  
  patch( 'faces', f, 'vertices', v )
  
  v.values = updateValues();
  drawnow
  </code></pre>
  
  <p>so whenever I change the values at one point, the patch also updates its values without having to explicitly go in and change the vertices field.</p>