MATLAB: Am I not able to save instances of the class to a MAT file

loadloadobjmatMATLABsave

I am trying to save instances of a class that I created to a MAT file using the "save" command.
The MAT file is generated successfully, but when I load it using the "load" command, the variable created in the workspace has the correct fields for an object of that type, but every field is blank – all the data is missing.
Why is the object not being saved correctly?

Best Answer

This issue is likely being caused by a loading problem rather than a problem using "save".
In order to load your custom object, you must have defined a "loadobj" method in your class. When a custom object is loaded from a MAT file, MATLAB looks for this method to know how to create the object based on the data present in the MAT file. Without this method, MATLAB is unable to load the data from the MAT file into the object.
You can read more about "loadobj" at the following documentation page: