Can I use a button to stop a GUI and the function and the script that started it?

3 次查看(过去 30 天)
Hello I'm sorry if there is an answer out there but I haven't been able to find it. I have a script which runs a script which calls a function which launches a GUI. Is it possible to have a button in the GUI that will exit the GUI, the function, and the script (basically an abort button)?
To exit the GUI I have: delete(handles.figure1) return;
but it seems that "return" runs the gui exit code because I get the following error when I hit the button:
??? Attempt to reference field of non-structure array.
Error in ==> a2_QueryLoopGUI>a2_QueryLoopGUI_OutputFcn at 74
varargout{1} = handles.output;
Any ideas? Do I have to pass an exit variable out through varargout to the function and then from the function into the script?
Thanks!

回答(1 个)

Sean de Wolski
Sean de Wolski 2012-3-29
Sure.
Have the GUI, on exit by pushing a quit button (or the red 'x'), return a flag that when returned, is checked for in the function, which return from the function etc.
Or just have it throw an error.
  3 个评论
Ben Ruppel
Ben Ruppel 2012-3-29
Okay, so for the record I ended up creating a abortStatus variable that travels all the way up the chain of calls in order to end everything. This seems like doing it the long way.
Learning how to return a value from the GUI along with exiting the GUI resuming flow control wasn't simple.
The guidelines for what worked for me are:
put uiwait(handles.figure1) in the xxx_OpeningFcn block
put the following 2 lines in the xxx_OutputFcn block:
-varargout{1} = handles.output;
-delete(handles.figure1)
put uiresume(handles.figure1) in the callback for any button that will result in the GUI closing, after anything else it does.
if you want to assign output data in a block of code (in the callback for a button for instance), assign the data like:
handles.output = 'outputtext';
then: guidata(hObject.handles) which makes the data you added to hObject "stick" to the shared data of the gui.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by