MATLAB Answers

How to save/restore state of App Designer app?

65 views (last 30 days)
I have an app with many different controls (~30). I would like users to be able to save the state of the app on closing the app. The user would then be able to restore the state of the app the next time that they run the program.
1) Is there a built-in way to make app state persistent in App Designer?
2) Is there a programmatic workaround that accomplishes this behavior? If so, is there a scalable solution that doesn't involve setting/initializing each individual control?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 May 2020
We don't have this functionality built into App Designer today. However, you could write specific code to do this. At a high-level, this would be:
On close:
- Loop over all components
- Store the relevant properties for that component into a struct (e.g. Value for edit field, Position for figure, SelectedObject / Value for radio buttons & a button group)
- Store the code name of the component in the same struct
- Store that struct into a "master" struct
- Save the "master" struct to a MAT-file
On load:
- Load the MAT-file
- Loop over all fieldnames of the "master" struct
- For each property stored in the component struct, assign the properties of the component with that code name
You would have to define which properties are relevant for each component.
See the attached MLAPP for an example.
  2 Comments
Ranjeet Nagarkar
Ranjeet Nagarkar on 29 Nov 2020
How do you store states for a button pressed? Can you share a file for it if possible. Thank you.

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by