title: Memoize a method of a class in matlab
body: <p>I have some code from a collegue, and I want to add caching to one of the class methods without chancing the original code. I think I should simply overload that function, and call a memoized version of the superclass function. An example:</p>
  
  <p><strong>A.m</strong></p>
  
  <pre class="lang-matlab prettyprint-override"><code>classdef A &lt; handle
      methods
          function res = foo(obj, arg)
              disp('class A')
              res = arg;  % expensive calculation
          end
      end
  end
  </code></pre>
  
  <p><strong>B.m</strong></p>
  
  <pre class="lang-matlab prettyprint-override"><code>classdef B &lt; A
      methods
          function obj = B()
              fn = @foo@A;
              obj.foo_m = memoize(fn);
          end
          function res = foo(obj, arg)
              disp('class B')
              obj.foo_m(arg)
          end
      end
  end
  </code></pre>
  
  <p>Now it complains about a an invalid operator in line:
  <code>fn = @foo@A;</code></p>
  
  <p>Furthermore I have the feeling that this might be an issue also: <a href="https://stackoverflow.com/a/21413098/1768422">https://stackoverflow.com/a/21413098/1768422</a></p>
  
  <p>How to solve this in an elegant/transparant way?</p>