I'm calling the print_num class from a GUI.
classdef print_num properties (SetAccess = private) flag = 0; n; end methods function obj = print_all(obj, n) %PRINT_ALL Prints numbers until interupted
obj.flag=0 obj.n = n disp('print_num function') i=1 while i<=obj.n if obj.flag == false fprintf('%i flag: %i\n', i, flag) pause(0.1) i=i+1; else break end end end function obj = stop(obj) %STOP Stop printing of numbers
disp('Stop function') obj.flag=1 end end end
I need want to stop the printing of numbers when stop() method is called. I'm calling both the methods print_all(n) and stop() from two pushbuttons of a GUI.
function multiprocessing_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; handles.p = print_num; guidata(hObject, handles);% --- Executes on button press in f1.
function f1_Callback(hObject, eventdata, handles) handles.p = handles.p.print_all(20); guidata(hObject, handles);% --- Executes on button press in f2.
function f2_Callback(hObject, eventdata, handles) disp('stop called') handles.p = handles.p.stop(); guidata(hObject, handles);
I'm unable to stop the printing of numbers with the flag property of the class print_num. Can someone explain me what I'm doing wrong?
Best Answer