function GUI_breakOP
GUI.fh = figure;
GUI.h1 = uicontrol('style','Edit',...
'string','XX',...
'Units','normalized',...
'Position',[0.1 0.1 0.8 0.2],...
'backgroundcolor','c',...
'Tag','EditField2',...
'Enable','off');
GUI.h2 = uicontrol('Style','PushButton',...
'String','Start',...
'Units','normalized',...
'Position',[0.1 0.4 0.3 0.2],...
'callback',{@func_compute},...
'Tag','StartButton',...
'backgroundcolor',...
'g','FontSize',12);
GUI.h3 = uicontrol('Style','PushButton',...
'String','Stop',...
'Units','normalized',...
'Position',[0.5 0.4 0.3 0.2],...
'callback',{@breakOP},...
'Tag','StopButton',...
'backgroundcolor',...
'r','FontSize',12);
myHandle = guihandles(GUI.fh);
myHandle.breakOP = false;
guidata(GUI.fh,myHandle);
end
function func_compute(~,~)
myHandle = guidata(gcbo);
myHandle.breakOP = false;
guidata(gcbo,myHandle);
if ~isempty(str2num(myHandle.EditField2.String))
a = str2num(myHandle.EditField2.String);
else
a = 1;
end
while 1
myHandle = guidata(gcbo);
myHandle.EditField2.String = num2str(a);
pause(0.01);
if myHandle.breakOP
break;
end
a = a +1;
end
end
function breakOP(~,~)
myHandle = guidata(gcbo);
myHandle.breakOP = true;
guidata(gcbo,myHandle);
end
Best Answer