title: Nested classdef with or without handle?
body: <p>I am trying to used updatable object (class) in Matlab with nested class. I observe a behavior that seems to be due to the handle status.</p>
  
  <p>I write the 2 classes <code>testA</code> and <code>testB</code>. <code>testB</code> is a the main class that calls the class <code>testA</code> as a property:</p>
  
  <pre><code>classdef testB 
      properties
          objA=testA;
      end
      methods
          function obj=testB()
              obj.objA
              if isempty(obj.objA.val)
                  obj.objA.val=5;
              else
                   obj.objA.val=obj.objA.val+5;
              end
          end
          function up(obj)
              obj.objA.val=obj.objA.val+6;
              obj.objA.val
          end
      end
  end
  </code></pre>
  
  <p>Firstly, <code>testA</code> is a handle class.</p>
  
  <pre><code>classdef testA &lt; handle 
      properties
          val=[];
      end
      methods
          function obj=testA()
          end
          function set.val(obj,tt)
              obj.val=tt;
          end
      end
  end
  </code></pre>
  
  <p>When I create <code>testB</code> object two times</p>
  
  <pre><code>tt=testB
  tt=testB
  </code></pre>
  
  <p>I observe that the <code>val</code> property in <code>testA</code> is not reinitialized (<code>val</code> in <code>testA</code> keeps the previous value). I am not sure but it seems to be due to the <code>handle</code> feature. The method <code>tt.up</code> increase the <code>val</code> property in <code>testA</code> as expected.</p>
  
  <p>Secondly if I change the <code>testA</code> class to a value class.</p>
  
  <pre><code>classdef testA  
      properties
          val=[];
      end
      methods
          function obj=testA()
          end
          function obj=set.val(obj,tt)
              obj.val=tt;
          end
      end
  end
  </code></pre>
  
  <p>In this case the successive calls of <code>tt=testB</code> create each time a new instance of <code>testB</code> with a new instance of <code>testA</code>. Unfortunately in this case the <code>up</code> methods does not work as expected (the new computed value of <code>val</code> is not stored in the object). </p>
  
  <p>A solution could be to consider <code>handle</code> class for <code>testA</code> and force to delete it before fully initialize the <code>testB</code> object. However I don't know how to do this. </p>