Filter löschen
Filter löschen

Delete Page of PDF Report from Report Generator

5 Ansichten (letzte 30 Tage)
Gwendolyn Williams
Gwendolyn Williams am 3 Jan. 2024
I'm trying to create a data quality report that generates automatically after I analyze a new set of data.
I want to put two imagesc figures on one page of the report. I'd like to add the figures to Section 1, Chapter 1 and so far I've found two ways to do this:
1. Create an "invisible table" and put images of each figure into the cells of the table, then add the table to the chapter section. This works, but I haven't gotten the sizing quite right to maximize the figures on the page using the following code:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('datarep','pdf');
tp = TitlePage;
tp.Title = [subject ' Data Report'];
tp.Author = 'G. Williams';
append(rpt,tp);
append(rpt,TableOfContents);
ch1 = Chapter;
ch1.Title = 'Displacement Data';
ch1.Layout.Landscape = true;
sec1 = Section;
sec1.Title = 'Peak Systole Displacement SI';
append(ch1,sec1)
imgStyle = {ScaleToFit(true)};
f1 = Figure();
imagesc(x_disp_syst) % x_disp_syst is 256x256 containing the data I want to visualize (1/2)
axis equal
axis tight
box off
colorbar
h = gca;
h.XTickLabel = [];
h.YTickLabel = [];
h.XAxis.Visible = 'off';
h.YAxis.Visible = 'off';
title('Peak Systole DispX')
% get snapshot of the imagesc figure to feed into the table
fig1Img = Image(getSnapshotImage(f1,rpt));
fig1Img.Style = imgStyle;
delete(gcf);
f2 = Figure();
imagesc(y_disp_syst) % 256x256 of data I want to visualize (2/2)
axis equal
axis tight
box off
colorbar
h = gca;
h.XTickLabel = [];
h.YTickLabel = [];
h.XAxis.Visible = 'off';
h.YAxis.Visible = 'off';
title('Peak Systole DispY')
% get snapshot of the imagesc figure to feed into the table
fig2Img = Image(getSnapshotImage(f2,rpt));
fig2Img.Style = imgStyle;
delete(gcf)
% feed snapshots if images into the table
lo_table = Table({fig1Img, fig2Img});
% set widths of table to determine size of images
lo_table.entry(1,1).Style = {Width('4.2in'), Height('5in')};
lo_table.entry(1,2).Style = {Width('4.2in'), Height('5in')};
lo_table.Style = {Width('100%'), ResizeToFitContents(false)};
append(sec1,lo_table)
append(rpt,ch1)
close(rpt)
rptview(rpt)
2. Using tiledlayout(), I can get the figures to look a bit nicer in the PDF and don't have to fiddle around with setting the height and width of the table to get it to look right, but the generated report has an extra blank page at the end that I don't understand, using the following code:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('datarep','pdf');
tp = TitlePage;
tp.Title = [subject ' Data Report'];
tp.Author = 'G. Williams';
append(rpt,tp);
append(rpt,TableOfContents);
ch1 = Chapter;
ch1.Title = 'Displacement Data';
ch1.Layout.Landscape = true;
sec1 = Section;
sec1.Title = 'Peak Systole Displacement SI';
append(ch1,sec1)
t1 = tiledlayout(1,2);
nexttile
imagesc(x_disp_syst)
axis equal
axis tight
box off
colorbar
h = gca;
h.XTickLabel = [];
h.YTickLabel = [];
h.XAxis.Visible = 'off';
h.YAxis.Visible = 'off';
title('Peak Systole DispX')
nexttile
imagesc(y_disp_syst)
cd(fnct_dir)
colormap(bluewhitered)
axis equal
axis tight
box off
colorbar
h = gca;
h.XTickLabel = [];
h.YTickLabel = [];
h.XAxis.Visible = 'off';
h.YAxis.Visible = 'off';
title('Peak Systole DispY')
t1.Padding = 'tight';
t1.TileSpacing = 'tight';
append(sec1,Figure)
append(rpt,ch1)
delete(gcf)
close(rpt)
rptview(rpt)
I can use the code from (1), but I need to create these reports with a number of variables that will require me to reisze the tables for each variable as I have this written.
If anyone could help direct me on either fixing the code from (1) to better show the figures without having to hardcode the height/widths, or if someone can help me understand why my tiledlayout code adds a blank page to my PDF so I can stop that, or there's a way to just tell matlab to delete the blank page after its created, I would greatly appreciate it.
I've been reading through the report generator documentation, but I've never really worked with object oriented code so it's a bit of a learning curve for me.
Thank you in advance!

Antworten (1)

Gwendolyn Williams
Gwendolyn Williams am 4 Jan. 2024
I figured out how to get multiple figures into one section, but they aren't next to eachother. So, the following code allows you to add as many figures to a section as you please:
import mlreportgen.report.*
import mlreportgen.dom.*
% create report called datarep
rpt = Report('datareptest','pdf');
ch1 = Chapter();
ch1.Title = 'Displacement';
% create a section
sec10 = Section;
sec10.Title = 'Hopeful with low expectations'
% create a named figure handle and plot your data
fig10b = figure();
plot(medulla_perm)
% use the report gen figure reporter
f10b = Figure(fig10b);
% append section 10 to have this figure
append(sec10,f10b)
delete(gcf)
% now make your nth figure the same way
fig10a = figure();
plot(pons_perm)
% use the report gen figure reported again
f10a = Figure(fig10a);
% append section 10 to have your nth figure
append(sec10,f10a)
% now you append section 10 into chapter 1
append(ch1,sec10)
% delete the figure again, if you don't the report will end using the same
% figure multiple times
delete(gcf)
% finally append chapter 1 to the report
append(rpt,ch1)
% close and view the report
close(rpt)
rptview(rpt)

Kategorien

Mehr zu MATLAB Report Generator Task Examples finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by