function out = setgetVar(data)
persistent Var;
if nargin
Var = data;
end
out = Var;
end
end
end
Set the value of the variable by calling setgetVar with an input argument. The method
assigns the input value to the persistent variable:
StoreData.setgetVar(10);
Get the value of the variable by calling setgetVar with no input argument:
a = StoreData.setgetVar
a =
10
Clear the persistent variable by calling clear on the StoreData class:
clear StoreData
a = StoreData.setgetVar
a =
[]
Add a method like setgetVar to any class in which you want the behavior of a static
property.
Static Data Object
To store more extensive data, define a handle class with public properties. Assign an
object of the class to a constant property of the class that uses the static data. This
technique is useful when you want to:
- Add more properties or methods that modify the data.
- Save objects of the data class and reload the static data.
Static Data