Stuart’s MATLAB Videos

Watch and Learn

Video: Saving the state of a GUI

A question that comes across my inbox from time to time is how to save the state of a GUI between session. There are few methods for doing this, one is using the HGSAVE command to save the .FIG file for the GUI. This can be done in a way that modifies the original .FIG file, or you can save a different one. Another way is to explicitly query each of the UICONTROLS for their value and then save those values in a structure. You can later reload and set the values. Personally, I am very willing to do more typing to get explicit control over activities like this. The saved state .MAT file is very readable, and would allow you to save state that might not be reflected in the UICONTROLS. Also, this helps to keep the saved data separate from the files that create GUI components. The modular architecture is appealing. Finally, for people that are building their entire GUI programmatically (that is, using UICONTROL to position widgets instead of GUIDE) this method is really useful because you do not ever really load a .FIG file.
Also, be sure to take some time to explore the new look of the File Exchange. Lots of new features.
  • print
  • send email


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.