Matlab class with knowledge of instance name in the constructor
<p>I would like to have a class which, in its constructor, can have knowledge  (extract as a string) its instance name. </p>

<p>For the moment I worked the name extraction out like this:</p>

<pre><code>classdef mysession

methods (Access = public)

  function this=mysession (varargin)
    this.cargs=varargin;
    this.built=false;
  end

  function id=build(this)
    id=this.mynameis;
    this.id = id;
    %% instructions needing id 
    built=true;
  end

  function name = mynameis (this)
    name=evalin ('caller', 'inputname');
  end
end

properties  (Access=private)
    id
    built
    cargs
end
end
</code></pre>

<p>which requires the ugly </p>

<pre><code>A = mysession;  A.build
</code></pre>

<p>syntax in order to work... </p>