Dear sir, How can I link between two interface or three interface of GUI? to make it more friendly user.
1 次查看(过去 30 天)
显示 更早的评论
1 个评论
Geoff Hayes
2015-10-15
Are you trying to launch one GUI from the other? Or is each "interface" a frame within a single GUI?
采纳的回答
Dennie
2015-10-16
This actually quite a complex problem, with a very simple solution. I've encountered the same problem a couple of years ago and solved it with some basic tricks. I do not know if this is the best approach but it works.
So I will assume that you have used GUIDE to generate the matlab scripts for the GUI.
First step is to make the handle of your GUI accessible in the root memory of your PC. This is a number that matlab uses to find the GUI from a different one. use this code in the opening func of the GUI and remember the name you give to this appdata:
setappdata(0,'<GUI_a>',gcf) % 0 denotes root memory of pc, gcf = get current figure handle
then later on where you want to open GUI b you use the following code to do so:
handles.gui_b=gui_b; %name of the gui_b.m, this opens GUI B
handles.gui_b_struct=getappdata(handles.gui_b); % save the handle of gui_b in gui_a
handles.gui_b_data=handles.gui_b_struct.UsedByGUIData_m; %extract the handle to the handle structure of gui_b
Now GUI A is linked to GUI B. In GUI B now we need to connect to GUI A. We can do this by using the initial handle of GUI_A that we saved in the root memory. In the opening function of GUI B use this code:
handles.GUI_A=getappdata(0,'GUI_a'); % retrieve handle of GUI_A
handles.GUI_A_struct=getappdata(handles.GUI_A); % retrieve handle to the structure used in GUI_A
handles.GUI_A_data=handles.GUI_A_struct.UsedByGUIData_m; % retrieve data inside the structure in GUI_A
This code links the data saved in the structure in GUI A, so you can read and write data in that structure from GUI B.
Now if you call GUI C from GUI B you repeat this process, but you will also need to place the handle of GUI B in the root memory like you have done for GUI A to link GUI C. just add this code to the opening function of GUI B and repeat the steps of linking inside GUI C:
setappdata(0,'<GUI_b>',gcf)
I hope this helps,
Dennie
4 个评论
Dennie
2015-10-19
Exactly, you can close GUI A within the callback that opens GUI B. I'm not sure if you lose also the data inside the handle structure of GUI A if you close it like this. If this is the case, you can simply save the entire handle structure from GUI A to your harddisk using the save command and reload it when opening GUI A
Geoff Hayes
2016-3-30
Clément - please post your comment as a new question since that is what it is.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!