Main Content

Save and Load Java Objects to MAT-Files

To save or serialize a Java® object to a MAT-file, call the save function. To load the object from a MAT-file back into MATLAB®, call the load function.

When you save or load a Java object, the object and its class must meet all this criteria:

  • The class implements the Java API Serializable interface, either directly or by inheriting it from a parent class. Any embedded or otherwise referenced objects also must implement Serializable.

  • Do not change the class definition between saving and loading the object. Changes to the data fields or methods of a class prevent the loading of an object that was constructed with another class definition.

  • Values in transient data fields are not saved with the object. Either the class does not have any transient data fields, or the values are not significant.

If you define your own Java classes, or subclasses of existing classes, follow the same criteria to enable saving and loading objects of the class in MATLAB. For details on defining classes to support serialization, consult your Java development documentation.

See Also