필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)

채택된 답변

Dennie
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
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
Geoff Hayes 2016년 3월 30일
Clément - please post your comment as a new question since that is what it is.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by