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 日

0 投票

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 日
Thanks, but this doesn't work. The loop only goes through k=1 and then it cancels the rest on its own.
Rik
Rik 2022 年 3 月 25 日
編集済み: Rik 2022 年 3 月 25 日
You could try using explicit handles:
h_f=figure('Visible', 'off');
ExpFig = trisurf(...
F,...
P(:,1),P(:,2),P(:,3),...
app.UITable4.Data(:,k),...
'Parent',h_f);
exportgraphics(h_f, string(file) ,"BackgroundColor","none","ContentType","vector","Append",true);
close(h_f);
If that doesn't help, try with a visible figure and step through your code line by line.
Pelajar UM
Pelajar UM 2022 年 3 月 25 日
編集済み: Pelajar UM 2022 年 3 月 25 日
Getting this error :(
Error using trisurf
Patch cannot be a child of Figure.
Also I must add that in my original code, all the frames (1:16) are exported. It's just that the cancel button doesn't do anything.
Rik
Rik 2022 年 3 月 25 日
Ah, I always forget this: you need to create an axes object first:
h_f=figure('Visible', 'off');
h_ax=axes('Parent',h_f);
ExpFig = trisurf(...
F,...
P(:,1),P(:,2),P(:,3),...
app.UITable4.Data(:,k),...
'Parent',h_ax);
exportgraphics(h_f, string(file) ,"BackgroundColor","none","ContentType","vector","Append",true);
close(h_f);
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 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

タグ

質問済み:

2022 年 3 月 25 日

コメント済み:

Rik
2022 年 3 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by