Closing a Gui with button whilst within a infinite while loop?
17 次查看(过去 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!