Closing a Gui with button whilst within a infinite while loop?
조회 수: 8 (최근 30일)
이전 댓글 표시
If I had a program like below I get error messages when trying to quit out of the GUI, why is this. I want it so that I can quit the program with no errors. I have seen examples of using uicontrol but how would I exit the while loop with a button already in the GUI?
function Generate_Callback(hObject, eventdata, handles)
% hObject handle to Generate (see GCBO)
% eventdata; reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
while(get(handles.Stop,'Value')==0)
C=str2num(get(handles.c,'string'));
axes(handles.graph);
x=0:0.1:4*pi;
y=sin(x+C);
plot(x,y);
pause(0.05);
end
% --- Executes on button press in Stop.
function Stop_Callback(hObject, eventdata, handles)
% hObject handle to Stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pause(0.1);
close all;
-----------------------------------------------
Errors
Error using matlab.ui.control.UIControl/get Invalid or deleted object.
Error in practice>Generate_Callback (line 81) while(get(handles.Stop,'Value')==0)
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in practice (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)practice('Generate_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating DestroyedObject Callback
댓글 수: 0
답변 (1개)
Adam
2016년 4월 29일
doc uicontrol properties
Look at the section on the Interruptible property. This is what you will need for the control that triggers the infinite callback. I don't have time to give examples or explain much, but the help gives detail on the scenarios that it covers.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!