How can I share data between two GUIs in MATLAB 8.0 (R2012b)?
4 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2012-11-15
编辑: MathWorks Support Team
2023-4-19
I have two GUIs: one is the parent GUI which calls the second (child) GUI. I want to share information between parent and the child GUI.
采纳的回答
MathWorks Support Team
2023-4-18
编辑:MathWorks Support Team
2023-4-19
Sharing data between two GUIs is illustrated by the following example in the MATLAB documentation:
Execute the following
web([docroot '/matlab/code-to-run-the-gui.html'])
at the MATLAB command prompt, and then click on the link:
Data Management in a GUIDE GUI
OR
Data Management in a Programmatic GUI
depending upon whether you used Graphical User Interface Development Environment (GUIDE) to create your GUIs or not.
One of the ways to share data between GUIs is explained below:
To share data between the parent GUI and the child GUI, you can make use of the SETAPPDATA and the GETAPPDATA functions in MATLAB. In the example code attached with this solution, "GUI1.fig" is the parent GUI which invokes "GUI2.fig" which is the child GUI. The child GUI shares the information entered in its EDIT box using the SETAPPDATA function as shown below:
b=get(handles.edit2,'String');
setappdata(0,'ReturnText',b);
delete(handles.figure1)
The parent GUI retrieves this information and displays it in its own edit box using the code shown below:
a=getappdata(0,'ReturnText')
set(handles.edit1,'String',a)
The child GUI is invoked from within the pushbutton callback of the parent GUI as shown below:
h = GUI2;
waitfor(h);
You may also refer to Video: GUIDE Basics Tutorial by Doug Hull posted on MATLAB Central
Regarding the MATLAB Central reference, please note that MATLAB Central is a user community and that MathWorks does not support the technical content posted on it, neither does it guarantee the accuracy of the content. Any questions about the content posted on MATLAB Central should be raised to the author directly.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!