add

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

Add content to report

Syntax

add(report,content)

Description

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

Note

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

Input Arguments

expand all

Report, specified as a report object. To create the report input, use mlreportgen.report.Report.

Report content, specified as Report API reporter objects and any object that can be added to a DOM document. Objects that can be added to a DOM document include DOM objects and many built-in MATLAB objects, such as strings, character arrays, and cell arrays.

Examples

Add Content to Report

Add a title, table of contents, chapter, and table to a report.

import mlreportgen.report.*
import mlreportgen.dom.*;
rpt = Report('Magic Square Magic');

add(rpt,TitlePage('Title','Magic Square Magic',...
     'Subtitle','Inverting a Magic Square'));
add(rpt, TableOfContents);

ch = Chapter('Magic Moments');
m = magic(5);
add(ch, BaseTable('Title','m = magic(5)',...
     'Content',m));
mInverse = m^-1;
add(ch,BaseTable('Title','mInverse = magic(5)^-1',...
     'Content',cellfun(@(x) sprintf('%0.3f', x),...
     num2cell(mInverse),'UniformOutput', false)));
add(ch, BaseTable('Title','m*mInverse','Content', ...
     cellfun(@(x) sprintf('%0.3f',x),num2cell(m*mInverse),...
     'UniformOutput',false)));

add(ch,Paragraph(sprintf(...
     'sum(m(1,:)) - sum(m(:,1)) = %d',...
     sum(m(1,:)) - sum(m(:,1)))));
add(ch,Paragraph(sprintf(...
    'sum(mInverse(1,:))- sum(mInverse(:,1)) = %0.3f',...
     sum(mInverse(1,:)) - sum(mInverse(:,1)))));

add(rpt,ch);
close(rpt);
rptview(rpt);

Introduced in R2017b