필터 지우기
필터 지우기

How to save uitable & uifigure into pdf file?

조회 수: 86 (최근 30일)
Tai Jia Xun
Tai Jia Xun 2018년 6월 22일
댓글: dpb 2023년 10월 10일
I am generating a table and graph using uitable and uifigure function, and I need to save the uitable and uifigure into pdf file. However, the pdf file was successfully generated but it's blank. Is there anyway to do that? My codes are as follow: ________________________________________________
fig = uifigure('Name','Numbers');
t = uitable(fig,'Data',[2,4,6,8;1,3,5,7]);
saveas(gcf,'Numbers','pdf')
________________________________________________

채택된 답변

Udit Dhand
Udit Dhand 2018년 6월 22일
fig = figure('Name','Numbers');
t = uitable(fig,'Data',[2,4,6,8;1,3,5,7]);
saveas(gcf,'Numbers','pdf')
Apparantly there is some problem with uifigure while setting it as parent of uitable.
  댓글 수: 2
Tai Jia Xun
Tai Jia Xun 2018년 6월 22일
it works!!!! thanks!!!!!!!!!
dpb
dpb 2023년 10월 10일
NOTA BENE: In
fig = figure('Name','Numbers');
t = uitable(fig,'Data',[2,4,6,8;1,3,5,7]);
saveas(gcf,'Numbers','pdf')
gcf does not necessarily return the same handle as fig -- even though it's highly likely it will, MATLAB instructions are not atomic and a selection of another figure could be made between the creation of fig and the execution of saveas. To be certain, use
saveas(fig,'Numbers','pdf')

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

추가 답변 (1개)

dpb
dpb 2023년 7월 3일
Since R2021b, see exportapp which will include uicontrols; prior functions could not.
In the original, gcf doesn't return the handle of a uifigure but either an existing figure, or if one isn't already open, it creates a new one--either way, it will NOT be the handle of any uifigure.
  댓글 수: 2
Alexander
Alexander 2023년 10월 10일
I am trying exactly this right now, but the text in a UITable (which is a child of the UIFigure) is not showing in the PDF that is generated. Are children's contents not rendered when using exportapp?
dpb
dpb 2023년 10월 10일
fig = uifigure('Name','Numbers');
t = uitable(fig,'Data',[2,4,6,8;1,3,5,7]);
exportapp(fig,'Numbers.pdf')
winopen('Numbers.pdf')
produced a pdf file with the above content in it...would have to see specific code to see what may have gone wrong in your case.

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

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by