Save and Load Enumerations
To see a list of enumeration names defined by a class, use the
Built-In and Value-Based Enumeration Classes
When you save enumerations that derive from built-in classes or that are value-based classes with properties, MATLAB® saves the names of the enumeration members and the definition of each member.
When loading these enumerations, MATLAB preserves names over underlying values. If the saved named value is different from the current class definition, MATLAB uses the value defined in the current class, and then issues a warning.
Simple and Handle-Based Enumeration Classes
When you save simple enumerations that have no properties, superclasses, or values associated with the member names or enumerations derived from the
handle class, MATLAB saves the names and any underlying values.
When loading these types of enumerations, MATLAB does not check the values associated with the names in the current class definition. This behavior results from the fact that simple enumerations have no underlying values and handle-based enumerations can legally have values that are different than those values defined by the class.
Causes: Load as
struct Instead of Object
If you add a new named value or a new property to a class after saving an enumeration, MATLAB does not warn during load.
If the changes to the enumeration class definition do not prevent MATLAB from loading the object (that is, all the named values in the MAT-File are present in the modified class definition), then MATLAB issues a warning that the class has changed and loads the enumeration.
In the following cases, MATLAB issues a warning and loads as much of the saved data as possible as a
MATLAB cannot find the class definition
The class is no longer an enumeration class
MATLAB cannot initialize the class
There are one or more enumeration members in the loaded enumeration that is not in the class definition
If the class is a value-based enumeration with properties and a property that exists in the file, is not present in the class definition
struct has these fields:
ValueNames— A cell array of strings, one per unique value in the enumeration array.
Values— An array of the same dimension as
ValueNamescontaining the corresponding values of the enumeration members named in
ValueNames. Depending on the kind of enumeration class,
Valuescan be one of the following:
If the enumeration class derives from a built-in class, the array class is the same as the built-in class. The values in the array are the underlying values of each enumeration member.
structarray representing the property name — property values pairs of each enumeration member. For simple and handle-based enumerations, the
structarray has no fields.
uint32array of the same size as the original enumeration. Each element is an index into the
Valuesarrays. The content of
ValueIndicesrepresents the value of each object in the original enumeration array.