Saving multiple figures together to a PDF

조회 수: 26 (최근 30일)
RD
RD 2022년 7월 8일
댓글: Adam Danz 2022년 7월 14일
Hello,
I am trying to print/export my multiple output figures to PDF. The figure contains a surface plot and an uitable. I thought exportgraphics function will do my work but it seems like it does not support UI components. The desired output is to have a PDF with all the figures on a new page as similar to how they are displayed in figure window.
x = (rand(36,1))/10;
box = struct('B1',x(1:9),'B2',x(10:18),'B3',x(19:27),'B4',x(28:36));
box = structfun(@(fld) reshape(fld,3,3),box,'UniformOutput',false);
box = struct2cell(box)';
rows = [50,100,150]; %Axis data
col = [1000,3000,5000]; %Axis data
rnames = {'50','100','150'}; % These are column names
cnames = {'1000', '3000', '5000'}; % These are row names
sz = size(box);
for idx = 1:sz(1,2)
list = box{idx};
fig = figure('Position',[100 100 600 550]);
axes('Parent',fig,'position',[.1,.4,.8,.55],'Visible','off');
surf(col,rows,list);
xlabel('xAxis');
ylabel('yAxis');
zlabel('zAxis');
t = uitable('Parent',fig,'Data',list,'ColumnName',cnames,...
'RowName',rnames,'Units','Normalized','position',[0.075,0.025,0.75,0.3]);
exportgraphics(fig,'output.pdf','Append',true);
end
Any ideas on how it can be done? I tried using export_fig but it needs Ghostscript installed and I cannot install any third party software.
Thanks for the help,

답변 (1개)

Adam Danz
Adam Danz 2022년 7월 14일
편집: Adam Danz 2022년 7월 14일
Thanks for providing the code! The question title makes it seems like you're plotting multiple figures but your code shows that you produce one figure with multiple components.
If you use a uifigure instead of a regular figure you can export the figure using exportapp.
fig = uifigure('Position',[100 100 600 550]);
ax = axes(fig,'position',[.1,.4,.8,.55],'Visible','off');
surf(ax,col,rows,list);
xlabel(ax,'xAxis');
ylabel(ax,'yAxis');
zlabel(ax,'zAxis');
t = uitable(fig,'Data',list,'ColumnName',cnames,...
'RowName',rnames,'Units','Normalized','position',[0.075,0.025,0.75,0.3]);
exportapp(fig,'output.pdf');
end
*not tested
However, exportapp does not have an append option. You could create a pdf with exportapp and then append the pdf with exportgraphics as long as the content supplied to exportgraphics does not contain uicomponents.
  댓글 수: 2
RD
RD 2022년 7월 14일
Hi Adam,
The reason i said multiple figures is because i have a loop which creates bunch of them and i want all of them exported to PDF or even html so that it iseasy to share. My end goal is to automate the process to avoid clicking on each figure and individually exporting them.
I exportgraphics didn't work directly because i have uitable, I will see if uifigure makes any difference.
Thanks,
Adam Danz
Adam Danz 2022년 7월 14일
I see, that makes sense. getframe might be useful too but I don't have time at the moment to map that out.

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

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by