a GUI keeps popping out after close command

1 次查看(过去 30 天)
Hello.
I have 2 GUIs (figure1 and figure2). I pass 1 data from figure1 to figure2 via a pushbutton in figure1. The input is a double type.
function pushbutton4_Callback(hObject, eventdata, handles)
figure2({input})
In figure2 opening function, I have
function figure2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to figure2 (see VARARGIN)
% Choose default command line output for figure2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes figure2 wait for user response (see UIRESUME)
% uiwait(handles.figure2);
stageNo = varargin{1};
In figure2, I also created a pushbutton to close figure2 after storing some data.
function cancelbutton_Callback(hObject, eventdata, handles)
user_response = modaldlg1('Title','Confirm Close');
switch user_response
case {'No'}
case 'Yes'
close(figure2)
end
However, everytime I click the cancelbutton, figure2 pops up again and gives me error:
Index exceeds matrix dimensions.
Error in protA_select2>protA_select2_OpeningFcn (line 68)
stageNo = varargin{1};
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in figure2 (line 40)
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
Error in figure2>cancelbutton_Callback (line 690)
close(figure2)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in protA_select2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)figure2('cancelbutton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Anyone ever experience this before?
I make the GUI via guide and for some reasons, I need to pass the input without setappdata.
Thanks a lot! :)
Elizabeth

采纳的回答

Adam
Adam 2016-5-11
编辑:Adam 2016-5-11
'figure2' is not defined in that scope.
I assume you want to use
handles.figure2
as the handle of your GUI to close.
  2 个评论
Elizabeth
Elizabeth 2016-5-12
Hello, Adam! Thanks for your help!
Usually I write
close(name)
to close the figure. In this case, the name is figure2. Does it have to do with the tag name? Because I just tried your suggestion with
close(handles.tag)
and it works.
I have another gui file made in GUIDE that works also with only close(filename). However, this particular file does not have input argument. Thanks a lot anyway! :)
Adam
Adam 2016-5-12
A GUIDE GUI you should close using the tag. I am surprised
close( name )
would ever work in that context because 'figure2' would just be expected to be a variable like any other.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by