MATLAB: How to save app data including a mix of data and figure handles

datafigureguidehandleMATLABr2014ar2014bsave

I'm using GUIDE and want to save all the settings in the app, including figure handles and data. However, it gives a warning message when I save a structure of handles and data using 'save':
Warning:
Saving graphics handle variables can cause the creation of very large files. To save graphics figures, use savefig.

Best Answer

Here is the reasoning behind the warning message which says that "saving graphics handle variables can cause the creation of very large files":
  • Using 'save' on a graphics handle in R2014a only saved a scalar double, so the file size was small, but no information about the figure was captured.
  • Using 'savefig' on a graphics object in R2014a saves a figure that is much larger than using save because it is capturing the information necessary to recreate the figure.
  • Using 'save' on a graphics handle in R2014b should create a file roughly comparable in size to using 'savefig' in R2014a, because you are storing all the information necessary to recreate the figure in the MAT file.
  • Using 'savefig' on a graphics handle in R2014b will create a file roughly twice the size of the file created using 'save', unless you use the "compact" flag, which will create a file that is almost identical in size to using 'save'.
If you are saving a structure which includes a mix of both graphics handles and data, which is not recommended, we would recommend the following to work around the warning message:
1) Go through the 'guidata' structure in your app and move all the custom data out of the 'guidata' structure into a separate structure.
2) During app run-time, you could use 'getappdata' and 'setappdata' similar to how you are using 'guidata' now, but this will allow you to store the custom data in a separate location, independent from the graphics object handles which are stored in the 'guidata' structure.
3) Instead of saving the 'guidata' structure, you could save the separate structure of data using the 'save' command and save the figure handles using 'savefig'.
4) If you want, in the GUIDE app's create function you could load the separate data from the MAT file and use 'setappdata' so you can work with the data similarly to how GUIDE apps work with 'guidata'.