Save and Load Enumerations - MATLAB & Simulink (original) (raw)

Main Content

Basic Knowledge

See the save and load functions and Default Save and Load Process for Objects for general information on saving and loading objects.

To see a list of enumeration names defined by a class, use the enumeration function.

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 these five cases, MATLAB issues a warning. In case 1, there are no defined results. In cases 2 through 5, MATLAB loads as much of the saved data as possible as astruct:

  1. MATLAB cannot find the class definition.
  2. The class is no longer an enumeration class.
  3. MATLAB cannot initialize the class.
  4. There are one or more enumeration members in the loaded enumeration that is not in the class definition.
  5. 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 Fields

In cases 2 through 5, the returned struct has these fields:

See Also

Topics