MATLAB Answers

Dear sir, How can I link between two interface or three interface of GUI? to make it more friendly user.

5 views (last 30 days)
fooozie mtlb
fooozie mtlb on 15 Oct 2015
Commented: Geoff Hayes on 30 Mar 2016

  1 Comment

Sign in to comment.

Accepted Answer

Dennie
Dennie on 16 Oct 2015
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 Comments

Show 1 older comment
Dennie
Dennie on 19 Oct 2015
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

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by