waitbar cancel doesn't work

조회 수: 1 (최근 30일)
Pelajar UM
Pelajar UM 2022년 3월 25일
댓글: Rik 2022년 3월 25일
First of all it seems that this is common issue. I read all the topics I could find on the forum here, but there was no clear answer.
Adding drawnow didn't work.
And, Yes, the function is interruptible.
f = waitbar(0,'Loading','Name','Exporting...',...
'CreateCancelBtn','setappdata(gcbf,''canceling'',0)');
for k = 1:16
if getappdata(f,'canceling') == 1
break
end
figure('Visible', 'off');
ExpFig = trisurf(F,P(:,1),P(:,2),P(:,3),app.UITable4.Data(:,k));
exportgraphics(gcf, string(file) ,"BackgroundColor","none","ContentType","vector","Append",true);
close;
waitbar(k/16, f, sprintf('Export Progress: %d %%', floor (k/16*100)));
pause(0.1);
drawnow();
end
delete (f);
msgbox('Export Completed!');

채택된 답변

Rik
Rik 2022년 3월 25일
You forgot to set the value first and you reversed 0 and 1:
f = waitbar(0,'Loading','Name','Exporting...',...
'CreateCancelBtn','setappdata(gcbf,''canceling'',1)');
setappdata(f,'canceling',0);
for k = 1:16
if getappdata(f,'canceling')
break
end
figure('Visible', 'off');
ExpFig = trisurf(F,P(:,1),P(:,2),P(:,3),app.UITable4.Data(:,k));
exportgraphics(gcf, string(file) ,"BackgroundColor","none","ContentType","vector","Append",true);
close;
waitbar(k/16, f, sprintf('Export Progress: %d %%', floor (k/16*100)));
pause(0.1);
drawnow();
end
delete (f);
msgbox('Export Completed!');
  댓글 수: 6
Pelajar UM
Pelajar UM 2022년 3월 25일
While the answer from VBBV works, it seems like you cannot get rid of uifigure. Your last comment did the job. So the accepted answer goes to you! :)
Rik
Rik 2022년 3월 25일
You're welcome

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by