but when I put "setappdata(h,'canceling');" before the loop it cancels it fine... so don't know what is happening here
waitbar cancel button does nothing!
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So I have this bit of code where I make a waitbar at the start with a cancel button. There is a bit to stop it if the waitbar is pushed, but if I run it it doesn't work - the button is pushed but it doesn't stop the calculation. What am I doing wrong?? Is it something to do with the waitbar handle h? Before I had it as handles.waitbar, but the same thing happened! Please help me!
while get(t,'UserData') tic; %Start a stopwatch timer. TIC and TOC functions work together to measure elapsed time. h = waitbar((time /handles.PARAMS.time_max), sprintf('%3.2f', (time /handles.PARAMS.time_max * 100) ),'CreateCancelBtn','setappdata(gcbf,''canceling'',1)'); setappdata(h,'canceling',0);
% does some stuff
if getappdata(h,'canceling') % Cancel button has been pressed
time = time + toc; % updating time duration of the calibration
Statut = true; % Indicating how ends the calibration
delete(h);
break
end
% do other calculations, not using waitbar
time = time + toc; % updating time duration of the calibration
pause(0.01); % In order to escape the loop if we press the "cancel button"
delete(h);
end
Respuestas (1)
Sean de Wolski
el 4 de Mzo. de 2015
gcbf
Is very dangerous and should be avoided all of the time. It could be a figure, it could be a button, axes etc, who knows! In general for an applicatiom, all of the g* functions should be avoided (gcf, gca, gco etc.) because they're dynamic.
Instead, hardwire the handle to the object whose appdata is being referenced:
fig = figure
setappdata(fig,'cancelling',false)
etc.
2 comentarios
Sean de Wolski
el 5 de Mzo. de 2015
This line probably does nothing
setappdata(gcbf,''canceling'',1);
This one does because h doesn't change
setappdata(h,'canceling',0);
use a variable for whatever you want gcbf to be referencing in the first setappdata and use it (probably h again?).
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!