Main Content

Create Report Programs

The MATLAB® Report Generator™ includes classes that allow you to create report generator programs. These programs can generate Word, HTML, and PDF reports. The programs must include certain items and can include some optional items, both of which are listed here and described at each associated link. For information on Report API and how it compares to the Document Object Model (DOM), see What Are Reporters?

Required Report Program Tasks and Elements

All report generator programs must:

Optional Report Program Tasks and Elements

Optionally, in report generator programs, you:

  • Import Report API classes, which enables using non-fully qualified Report API class names, for example, TitlePage, instead of mlreportgen.report.TitlePage. See Import API namespaces.

  • Import DOM API classes, if the program adds DOM objects to the report, which enables using non-fully qualified DOM API class names.

  • Configure reporters by setting their property values. See Content Generation.

  • Add content to reporters by using the add method.

    Note

    The only reporters you can both configure and add content to are the Section and Chapter reporters. The Chapter reporter is a subclass of the Section reporter.

  • Display the report to see the generated report output. See Display Reports.

  • Display report progress messages to monitor report progress. See Display Progress and Debugger Messages.

Report Generator Program Example

For example, this MATLAB code generates and displays a PDF report. It includes both required and optional items:

Run the following command to access the supporting files used in this example.

openExample('rptgen/MatlabReportGeneratorSupportFilesExample');
% Import report API classes (optional)
import mlreportgen.report.*

% Add report container (required)
rpt = Report('output','pdf');

% Add content to container (required)
% Types of content added here: title 
% page and table of contents reporters
titlepg = TitlePage;
titlepg.Title = 'My Airplane';
titlepg.Author = 'Pilot A';
add(rpt,titlepg);
add(rpt,TableOfContents);

% Add content to report sections (optional)
% Text and formal image added to chapter
chap = Chapter('Plane Image');
add(chap,'Here is the plane:');
add(chap,FormalImage('Image',...
    which('b747.jpg'),'Height','5in',...
    'Width','5in','Caption','Boeing 747'));
add(rpt,chap);

% Close the report (required)
close(rpt);
% Display the report (optional)
rptview(rpt);

Report title page with the title "My Airplane", the author "Pilot A", and the date

Table of contents listing one image

A Boeing 747

Related Topics