problem with waitbar cancel button

2 ビュー (過去 30 日間)
Jim O'Doherty
Jim O'Doherty 2012 年 10 月 5 日
コメント済み: Ali Yar Khan 2020 年 1 月 31 日
All,
I'm encountering a little problem with a cancel button on a waitbar. I can get the Matlab example in the help file to work perfectly, although for some reason when I try it in my code, it does not seem to acknowledge the callback for the cancel button. Heres what I have:
hWaitBar = waitbar(0, '',...
'Name', 'LOADING IMAGES - PLEASE WAIT...',...
'CreateCancelBtn','setappdata(gcbf,''Canceling'',1)');
setappdata(hWaitBar,'Canceling',0)
for i=3:size(filelist,1)
%do stuff here
getappdata(hWaitBar,'Canceling')
% Check for Cancel button press
ch = getappdata(hWaitBar, 'Canceling')
if getappdata(hWaitBar,'Canceling') ==1
break
end
waitbar(i/size(filelist,1),hWaitBar)
end
delete(hWaitBar)
The check command 'getappdata(hWaitBar,'Canceling')' inside the loop never returns the value of 1, which it should do from the callback defined in hWaitBar.
The only difference I can think of between the matlab example and my code is that all my above code is located in a set if-else loops (4 deep). Would this be responsible?
Thanks
Jim

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 10 月 5 日
Try adding a drawnow() call inside the loop, so that the callback of canceling the waitbar will have a chance to run.
  1 件のコメント
Jim O'Doherty
Jim O'Doherty 2012 年 10 月 9 日
Thanks for the answer - no luck with the drawnow() command unfortunately. I think the issue is that when I actually press the cancel button, it doesn't change the "Canceling" variable to 1, and hence the callback doesn't run.

サインインしてコメントする。


Alexander Kosenkov
Alexander Kosenkov 2016 年 5 月 30 日
The currently running function must be started from a button/menu, where Interruptible is set to 'on'. Otherwise, currently running calculation (the one that opened the progress bar) can not be interrupted even to set 'Canceling' to 1.
  1 件のコメント
Ali Yar Khan
Ali Yar Khan 2020 年 1 月 31 日
can you share the code how can we set it on from the callee function ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by