Closing a Gui with button whilst within a infinite while loop?
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Adam
on 29 Apr 2016
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!