GUI inside another GUI

조회 수: 4(최근 30일)
Clément P
Clément P 2016년 3월 30일
댓글: Clément P 2016년 3월 31일
Hi everyone,
I want to open a GUI (GUI_Retrait) in my first GUI (GUI3) but I have trouble with it. I use GUIDE for GUI3 and I create GUI_Retrait without GUIDE.
To call GUI_Retrait I use the method described here :
I have an error in my first GUI when I'm calling the second one. The error is :
Error using getappdata
Value must be a handle.
Error in GUI3>Retrait_Callback (line 279)
handles.GUI_Retrait_struct=getappdata(handles.GUI_Retrait); % save the handle of
gui_b in gui_a
Error in gui_mainfcn (line 96)
Error in GUI3 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
Error while evaluating uicontrol Callback
I think I don't create my second GUI (GUI_retrait) the right way. I don't know how to create the handle of the GUI itself.
Does someone know how to fix this?
Here is the code of my second GUI : (I have several checkboxes which depend on a number given by GUI3)
function handles=GUI_Retrait
%Retrive Datas from GUI3
handles.GUI3=getappdata(0,'GUI3'); % retrieve handle of GUI_A
handles.GUI3_struct=getappdata(handles.GUI3); % retrieve handle to the structure used in GUI_A
handles.GUI3_data=handles.GUI3_struct.UsedByGUIData_m; % retrieve data inside the structure
handles.GUI_Retrait.h=figure('Name','Eprouvette(s) à retirer','NumberTitle','off','Position',[300 300 300 400]);
handles.GUI_Retrait.pb=uicontrol('Parent',handles.GUI_Retrait.h,'Style', 'Pushbutton',...
'String', {'Retirer'},...
'Position', [150 100 120 50],...
for i=1:handles.GUI3_data.n
str=sprintf('Eprouvette n°%s',num2str(i));'Parent',handles.GUI_Retrait.h,...
'Style', 'checkbox',...
'String', {str},...
'Position', [20 400-50*i 100 50]);
Thanks. Clément
  댓글 수: 2
Clément P
Clément P 2016년 3월 31일
편집: Clément P 2016년 3월 31일
Hi Adam,
Thanks for your answer.
It is right that I didn't created the handles first. Now I have added the line :
But I still have the same error. I assume GUIDE is doing something that I'm not doing right manually in GUI_Retrait. I also tried the command "handles=guihandles" but I still have the same error.

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

채택된 답변

Orion 2016년 3월 30일
When you call your second gui (GUI_Retrait), do you first close the main gui ?
If so, the error message is normal.
For what I understand, when you create the main GUI, you stock the handle in the appdata of the root (setappdata(0,'GUI3',yourHandle)). So the handle is stored. But if you close the main figure, the value of the handle is still stored, but the GUI doesn't exist anymore, so you can't use the value as a handle.
to be clear, test this :
f = figure;
ishandle(f) % the answer is 1
close(f); % destroy the object
ishandle(f) % the answer is 0
f still exist but is not a handle anymore.
Is this the problem you have ?
  댓글 수: 9
Clément P
Clément P 2016년 3월 31일
Ahah ! First time I'm lucky with Matlab :D
Thanks again !

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

추가 답변(0개)


Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by