Closing gui window *.gif
조회 수: 1 (최근 30일)
이전 댓글 표시
I created gui that has uipanel with two radio buttons. I'm running two endless loops for each radio button that know to switch on from another smoothly. When I close gui window I get errors as follows:
??? Error using ==> guidata at 89
H must be the handle to a figure or figure descendent.
Error in ==> Demo>uipanel1_SelectionChangeFcn at 262
guidata(hObject, handles);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Demo at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)Demo('uipanel1_SelectionChangeFcn',get(hObject,'SelectedObject'),eventdata,guidata(get(hObject,'SelectedObject')))
Error in ==> hgfeval at 63
feval(fcn{1},varargin{:},fcn{2:end});
Error in ==> uitools.uibuttongroup.childAddedCbk>manageButtons at 80
hgfeval(cbk, source, evdata);
??? Error while evaluating uicontrol Callback
Can you suggest what is the proper way to close gui window?
Thanks,
댓글 수: 5
Jan
2012년 7월 25일
Let me ask again: Do you assume, that the value of button1 or button2 is changed, during Matlab processes the infinite loop? Or in other words, is your function equivalent to:
if button1
while true
...
end
end
답변 (3개)
Jan
2012년 7월 24일
A secure solution would be:
- Create two flags in the figure's local data:
setappdata(FigureHandle, 'LoopEntered', false);
setappdata(FigureHandle, 'StopLoop', false);
- Enable a flag, when one of the loops is started:
setappdata(FigureHandle, 'LoopEntered', true)
- When the endless loop is finished (at least when this is not a contradiction...), disable the flag again:
setappdata(FigureHandle, 'LoopEntered', false)
- Inside the CloreRequestFcn and DeleteFcn (called when the figure is closed or deleted) set another flag to stop the loops:
if getappdata(FigureHandle, 'LoopEntered')
setappdata(FigureHandle, 'StopLoop');
while getappdata(FigureHandle, 'LoopEntered')
pause(0.1);
end
end
- Inside the loops, check the stop flag:
while XYZ
if get(FigureHandle, 'StopLoop')
break;
end
...
end
setappdata(FigureHandle, 'LoopEntered', false);
Then you have two dynamic locks: The running loop locks the closing of the figure. Closing the figure blocks the execution of the loop.
댓글 수: 2
Jan
2012년 7월 24일
Even GUIDE figures are 100% full and complete Matlab figures. There is not even one spark of magic added by GUIDE. Therefore it does not matter, if you create the figure directly by a program, or if you let GUIDE create the program to create the figure.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!