Main Content



Add content to report

Since R2020b




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


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 reporter to one report, you cannot add it to another report.

Input Arguments

expand all

Report, specified as an 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 vectors, and cell arrays.


expand all

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

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

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"));

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.


Close and view the report.


Version History

Introduced in R2020b