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.


Package: mlreportgen.dom

Copy paragraph object


clonedPara = clone(sourcePara)



clonedPara = clone(sourcePara) copies (clones) the specified paragraph. The resulting cloned paragraph includes the children of the source paragraph, but not the parent.


collapse all

import mlreportgen.dom.*;
d = Document('myDoc','html');

para1 = Paragraph('This is a paragraph');
para1.Bold = true;
para1Copy = clone(para1);
para1Copy = 
  Paragraph with properties:

        OutlineLevel: []
                Bold: 1
              Italic: []
               Color: []
     BackgroundColor: []
           Underline: []
          WhiteSpace: []
      FontFamilyName: []
            FontSize: []
              Strike: []
              HAlign: []
     OuterLeftMargin: []
     FirstLineIndent: []
           StyleName: []
               Style: {[1x1 mlreportgen.dom.Bold]}
    CustomAttributes: []
              Parent: []
            Children: [1x1 mlreportgen.dom.Text]
                 Tag: 'dom.Paragraph:2716'
                  Id: '2716'

Input Arguments

collapse all

Paragraph object to copy, specified as an mlreportgen.dom.Paragraph object.

Output Arguments

collapse all

Copied paragraph object, represented by an mlreportgen.dom.Paragraph object.


  • Use the clone method to append the same paragraph content more than once in a document.

  • When you clone a paragraph, DOM copies all of the children objects of the source paragraph, but not the parent of the paragraph.

  • The cloned paragraph includes formats that you set in the source paragraph. The cloned paragraph formats use the same format objects as the source paragraph. If you change the format setting in the shared format object, the source and cloned paragraphs reflect that change.

    If you change a format setting in the cloned paragraph, then DOM creates a new format object for the cloned paragraph, using the new format setting. For that format, the source and cloned paragraph no longer share the same format object.

    This example shows the relationship between the formats for the source and cloned paragraphs.

    1. Create a paragraph that uses a style that sets the Bold and Italic formats to true.

      import mlreportgen.dom.*;
      myReport = Document('myDoc','html');
      p = Paragraph('This is a paragraph');
      MyStyle = {Bold,Italic};
      p.Style = MyStyle;
      ans =
      ans =
    2. Clone the paragraph. The Bold and Italic formats are the same as those of the source paragraph.

      pClone = clone(p);
      ans =
      ans =
    3. For the cloned paragraph, change turn off bold text. The change to the Bold format in the cloned paragraph does not affect the text for the source paragraph. The source paragraph text is still bold.

      pClone.Bold = false;
      ans =
    4. In the style object (MyStyle) for the source paragraph, turn off italics. Now the cloned paragraph does not use italics, because it shares the MyStyle setting for the Italics format.

      MyStyle(2).Value = false
      ans =

Introduced in R2014b