Saving multiple figures together to a PDF

6 views (last 30 days)
RD
RD on 8 Jul 2022
Commented: Adam Danz on 14 Jul 2022
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,

Answers (1)

Adam Danz
Adam Danz on 14 Jul 2022
Edited: Adam Danz on 14 Jul 2022
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 Comments
Adam Danz
Adam Danz on 14 Jul 2022
I see, that makes sense. getframe might be useful too but I don't have time at the moment to map that out.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!