Main Content

append

Class: mlreportgen.report.Report
Package: mlreportgen.report

Add content to report

Syntax

append(report,content)

Description

append(report,content) adds the specified content to the specified report. If the report is not already open, the append method opens it.

Note

You can add a reporter to a report multiple times, but you cannot add the reporter to different reports. For example, if you add an mlreportgen.report.TitlePage reporter to one report, you cannot add it to another report.

Input Arguments

expand all

Report, specified as an mlreportgen.report.Report object.

Content to add to report, specified as a Report API reporter, DOM object, or built-in MATLAB® object. The content can be a Report API reporter or any object that you can append to a DOM document. Content that you can append to a DOM document includes DOM objects and many built-in MATLAB objects, such as strings, character arrays, and cell arrays.

Examples

expand all

This example adds a title page, table of contents, and chapter to a report by using the append method of the mlreportgen.report.Report object. To add content to the chapter, the example uses the append method of the mlreportgen.report.Chapter object.

Import the DOM and API packages so that you do not have to use long, fully qualified class names.

import mlreportgen.report.*
import mlreportgen.dom.*;

Create a report and add a title and table of contents to the report.

rpt = Report("Magic Square Magic");
append(rpt, TitlePage("Title","Magic Square Magic","Subtitle", ...
    "Inverting a Magic Square","Author","John Doe"));
append(rpt,TableOfContents);

Create a chapter and add content to the chapter.

ch = Chapter("Magic Moments");
m = magic(5);
append(ch,BaseTable("Title","m = magic(5)","Content", m));
mInverse = m^-1;
append(ch,BaseTable("Title","mInverse = magic(5)^-1","Content", ...
    cellfun(@(x) sprintf("%0.3f", x),num2cell(mInverse), ...
    "UniformOutput", false)));
append(ch,BaseTable("Title", "m*mInverse","Content", ...
    cellfun(@(x) sprintf("%0.3f", x),num2cell(m*mInverse), ...
    "UniformOutput", false)));
append(ch, Paragraph(sprintf("sum(m(1,:)) - sum(m(:,1)) = %d", ...
    sum(m(1,:)) - sum(m(:,1)))));
append(ch, Paragraph(sprintf("sum(mInverse(1,:)) - sum(mInverse(:,1)) = %0.3f", ...
    sum(mInverse(1,:)) - sum(mInverse(:,1)))));

Add the chapter to the report.

append(rpt,ch);

Close and view the report.

close(rpt);
rptview(rpt);
Introduced in R2020b