This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Add Content to a Report

Note

For a list of and detailed information about the content types you can add to and format for your report, see Content Generation.

Add Content to a Report API Object

The Report API add method allows you to add content to reports, chapters, sections, tables, and other Report API objects that serve as containers for report content. The add function takes two arguments. The first argument is the object to which to add the content. The second is the content to add. This example adds the text Hello World to a chapter.

chap = Chapter('First Chapter');
add(chap,'Hello World');

If you cannot add the second object to the first, the add function returns an error. For example, the add method in this code returns an error because you cannot add a chapter to an image.

% This code returns an error
image = FormalImage('membrane.png');
ch = Chapter('Membrane Image');
add(image,ch)

The reference documentation for each class lists the types of objects that you can add to instances.

Depending on the target object type, the add method allows you to append character vectors, doubles, arrays, and other basic MATLAB® data types directly. The method converts the data to a DOM object before adding it to the target object. For example, this code adds a two-dimensional array of character vectors and images to a document as a table.

rpt = Report();
img1 = Image(which('b747.jpg'));
img2 = Image(which('peppers.png'));
table = BaseTable({'Boeing 747' 'Peppers';img1,img2});
add(rpt,table);

Add Content to a DOM Object

The DOM append method allows you to add content to documents, paragraphs, tables, and other DOM objects that serve as containers for report content. The append function takes two arguments. The first argument is the object to append the content to. The second is the content to append. This example appends the text Hello World to the document.

d = Document('MyReport');
append(d,'Hello World');

If you cannot append the second object to the first, the append function returns an error. For example, the append method in this code returns an error because you cannot append a paragraph to an image.

% This code returns an error
image = Image('membrane.png');
append(image,Paragraph('Hello World'));

The reference documentation for each class lists the types of objects that you can append to instances.

Depending on the target object type, the append method allows you to append character vectors, doubles, arrays, and other basic MATLAB data types directly. The method converts the data to a DOM object before appending it to the target object. For example, this code appends a two-dimensional array of character vectors to a document as a table.

d = Document('MyDoc');
tableArray = {'a','b';'c','d'};
append(d,tableArray);

You can also specify basic MATLAB data types as initial content for many constructors. This example uses a two-dimensional cell array of characters to specify the initial content of a table.

d = Document('MyDoc');
tableArray = {'a','b';'c','d'};
append(d,Table(tableArray));	

See Also

Functions

Related Topics