How to save/restore state of App Designer app?

53 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 7 Mai 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.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by