How can I share data between two GUIs in MATLAB 8.0 (R2012b)?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 15 Nov. 2012
Bearbeitet: MathWorks Support Team
am 19 Apr. 2023
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.
Akzeptierte Antwort
MathWorks Support Team
am 18 Apr. 2023
Bearbeitet: MathWorks Support Team
am 19 Apr. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Files and Folders finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!