Borrar filtros
Borrar filtros

Saving multiple figures together to a PDF

26 visualizaciones (últimos 30 días)
RD
RD el 8 de Jul. de 2022
Comentada: Adam Danz el 14 de Jul. de 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,

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by