title: How to obtain static member variables in MATLAB classes?
body: <p>Is there a way to define static member variables in MATLAB classes?</p>
  
  <p>This doesn't work:</p>
  
  <pre><code>classdef A
  
      properties ( Static )
          m = 0;
      end
  end
  </code></pre>
  
  <p>It suggests to use keyword "Constant" instead of "Static", the constant properties cannot be modified. I want a variable common to all objects of class <code>A</code> and I want to be able to modify that variable in methods of class <code>A</code>.</p>
  
  <p>So what I need is a private static member variable. Is there a way to obtain it in MATLAB?</p>
  
  <hr>
  
  <p><strong>Found out that a workaround can be done</strong> using persistent variables in static member functions.</p>
  
  <p>In this case you should inherit all your classes from a base class like the following.</p>
  
  <pre><code>classdef object &lt; handle
  
      properties ( GetAccess = 'public', SetAccess = 'private' )
          id
      end
  
      methods ( Access = 'protected' )
          function obj = object()
              obj.id = object.increment();
          end
      end
  
      methods ( Static, Access = 'private' )
          function result = increment()
              persistent stamp;
              if isempty( stamp )
                  stamp = 0;
              end
              stamp = stamp + uint32(1);
              result = stamp;
          end
      end  
  end
  </code></pre>