How can I share data between two GUIs in MATLAB 8.0 (R2012b)?

4 ビュー (過去 30 日間)
MathWorks Support Team
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
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 件)

カテゴリ

Help Center および File ExchangeFiles and Folders についてさらに検索

タグ

製品


リリース

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by