Is it possible to save data in my MATLAB GUI and retrieve that data the next time I open the GUI?
2 次查看(过去 30 天)
显示 更早的评论
When I close my GUI, I would like to save the information that is contained in some of my UICONTROLS and then have that data available when I run the GUI again. I would like to know if there is an option in GUIDE that will allow me to do this.
采纳的回答
MathWorks Support Team
2010-1-20
This ability is not directly available in MATLAB.
As a workaround, you can save the data to a MAT file which can be loaded when the GUI is opened.
The attached files contain a basic example with a slider and an edit text box in the GUI. When the CloseRequestFcn is called on the GUI to end a session, values of the the editbox 'String' property and the slider 'Value' property will be saved to a MAT file. When the next GUI session is opened, the values will be loaded and used to set the GUI properties.
Please run the attached GUI by downloading the files to your MATLAB path and typing 'preference_saving_gui' at the MATLAB command prompt. After the GUI appears, make changes to the text box and slider control. Then close the GUI and notice that a MAT file has been created containing the saved property values. Rerun the file, and note that the old setting should be loaded. The command window will show messages indicating what has happened when opening and closing the GUI.
Please see the following functions in the attached GUI program file to understand how this GUI was implemented:
1) edit1_Callback
2) slider1_Callback
3) figure1_CloseRequestFcn
4) preference_saving_gui_OpeningFcn
Attached Files:
1) preference_saving_gui.m
2) preference_saving_gui.fig
Another example that also implements the similar behavior but in a slightly different manner:
1) reloading_param.fig
2) reloading_param.m
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!