MATLAB: How to stop a for loop execution from GUI?(From Toolbar stop button)

MATLABmatlab gui

I have for loop,,I want to to stop this loop from a toolbar button,, Initially I have set a flag "STOP=0",,,and when I press my stop button in tool bar,,I am calling a function,,where "STOP=1" I have written script,,,,But my script is not considering this"STOP" flag,,,please hep me out>…

Best Answer

You can write your flag in the UserData-property of the toolbaricon.
...
set(handles.uitoolbar1,'UserData',0)
for ...
if get(handles.uitoolbar1,'UserData')
break
end
end
...
function uipushtool1_ClickedCallback(hObject, eventdata, handles)
set(handles.uitoolbar1,'UserData',1)