Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can not, it is by design. You should use a <code>persistent</code> variable (technique from the MATLAB as 1980 applied in year 2011)!</p> <p>For completeness I should mention that actually there is as of 2010b an undocumented and probably not longer supported <code>static</code> property modifier.</p> <p>For background see <a href="http://www.mathworks.de/matlabcentral/newsreader/view_thread/171344" rel="noreferrer">here</a> the answer of <a href="http://blogs.mathworks.com/loren/2011/03/08/common-design-considerations-for-object-properties/" rel="noreferrer">Dave Foti</a>, MATLAB OO group manager:</p> <blockquote> <p>In MATLAB, classes can define Constant properties, but not "static" properties in the sense of other languages like C++. There were beta releases that experimented with "Static" properties and the undocumented attribute remains from then. However, the Static attribute is undocumented, should not be used, and will likely be removed in a future MATLAB release. R2008a implements it as a synonym for Constant and provides no additional functionality beyond the documented behavior of Constant properties.</p> <p>Constant properties may not be changed from the initial value specified in the property declaration. There are a couple of reasons why MATLAB works the way it does. First, MATLAB has longstanding rules that variables always take precedent over the names of functions and classes and that assignment statements introduce a variable if one doesn't already exist. Thus, any expression of the form "A.B = C" will introduce a new variable A that is a struct array containing a field B whose value is C. If "A.B = C" could refer to a static property of class A, then class A would take precedent over variable A and this would be a very significant incompatibility with prior releases of MATLAB. It would mean that an m-file containing the assignment statement "A.B = C" could have its meaning changed by the introduction of a class named A somewhere on the MATLAB path. MATLAB programmers have always been able to rely on assignment statements introducing variables that shadow any other use of the same name.</p> <p>Second, we have observed that static data is rarely used in other classes except as private data within the class or as public constants. For example, a survey of several Java class libraries found that all public static fields were also final. In MATLAB, Constant properties can be used like "public final static" fields in Java. For data internal to a class, MATLAB already has persistent variables that can be created inside of private or protected methods or local functions privately used by a class. There are also good reasons to avoid static data in MATLAB where possible. If a class has static data, it can be difficult to use the same class in multiple applications because the static data can be a source of conflicts among applications. In some other languages, this is less of an issue because different applications are separately compiled into executables running in different processes with different copies of class static data. In MATLAB, frequently many different applications may be running in the same process and environment with a single copy of each class.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload