GUI - How to interrupt an endless loop with another callback
Afficher commentaires plus anciens
Hello, I have some truble interrupting an animation in a GUI I wrote. The loop gets called by some Button1 like this
sd = 1;
loop_running = true;
KW=0;
axes(handles.axes1)
while loop_running
if KW+sd>size(KnM,3)
sd=-1;
elseif KW+sd==0
sd=1;
end;
KW = KW+sd;
scatter3(scatter information);
axis([0 0.2 -0.1 0.1 -0.1 0.1])
handles.KW = KW;
set(handles.edit8,'String',num2str(KW));
guidata(hObject,handles);
pause(PauseTime);
if isfield(handles,'Pause')
if handles.Pause
break;
end;
end;
%loop_running=handles.loop_running;
end;
Then there is my Pause Button
global test
if isfield(handles,'Pause')
if handles.Pause
handles.Pause = false;
else handles.Pause
handles.Pause=true;
end;
else
handles.Pause = true;
end;
test=1;
guidata(hObject,handles);
Button1 is interruptible, so when PauseButton is clicked, at pause(PauseTime); the PauseButton script runs, creates the handles.Pause field, BUT gets kinda deleted right afterwards, so the if isfield(handles,'Pause') is always false. I also tried to set loop_running=false with the same result. Its just like the callback of PauseButton never happens even though when debugging I can see the handles.Pause is created, but just as well beeing deleted right afterwards(same with that global variable I tested). The other answers I found, had a similar scipt or way to approach interrupting a loop.
Can somebody tell me what Im missing?
Many thanks in advance!! :)
Réponses (1)
Mr Anderson
le 3 Avr 2016
0 votes
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!