I developed a GUI and I have included a Stop button and its callback I have declared a global variable "StopOptim" and gave it a value 1; My idea is during the call to OutputFcn… I should be able to turn the logical variable stop to true if the button is pressed so that my optimization process stop gracefully and I recover whatever info i get thust far. for ex. i have maxIter =100 and i see things are not moving much by iter =20 then i would like to change the stop to true. so i press the gui stop button to change the initially set value of false to StopOptim variable to true and check that at the end of each OutputFcN. since the code is long I just give the relevant portions only here:
function stop=ViOptResults(x,optimValues,state)
global history VarScale Var Act
global StopOptim handles
stop = false;
—-
—-
drawnow();
stop=StopOptim;
end
so basically if the push button is pressed StopOptim turns the initial vaule of false into true for stop which is used by Optimization process to stop at that iteration gracefully. However, my problem is no matter how many times and how hard i try clicking on stop button, it does not seem to work and StopOptim is always remaining as false and the execution keeps continuing as if nothing happened. Here is my Stop button code.
function OptimStop_Callback(hObject, eventdata, handles) — global StopOptim
handles.OptimStop= 1;
StopOptim=1;
guidata(hObject, handles); % Update handles structure
I have been struggling with this quite some time now. I am sure it is a simple thing but somehow I am missing. Please help. Thanks in advance.
Best Answer