Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Report Generator   

Adding Components to the Report Template

About Components

Report components specify what information you want to include in the report. The following figure shows a sample page from the report you create in this tutorial and what components are used to produce it.

Setting Initial Values

To specify the sizes of the magic squares in the report, use the Evaluate MATLAB Expression component.

  1. In the Outline pane on the left, select the top level of the report template.

  2. In the Options pane in the middle, under the MATLAB category, select Evaluate MATLAB Expression.

  3. In the Properties pane on the right, click the icon next to Add component to current report to insert it into the report.

    You cannot edit the component information in the Properties pane until you have added the component to the report.

    In the Outline pane on the left, the Eval component appears under the magic_squares report.

    The icon in the upper left corner of the Eval component indicates that this component cannot have child components. By default, any components you add with the Eval component selected are siblings to this component.

    The options for the Evaluate MATLAB Expression component appear in the Properties pane on the right.

  4. Clear the Insert MATLAB expression in report and Display command window output in report check boxes. You do not want to include the MATLAB code details or its output in this report.

  5. In the Expression to evaluate in the base workspace text box, replace the existing text with the following M-code.

      Tip   Copy and paste this text from the HTML documentation into the Report Explorer.

    %This M-code sets up two variables
    %that define how the report runs.
    %magicSizeVector is a list of MxM
    %Magic Square sizes to insert into
    %the report. Note that magic
    %squares cannot be 2x2.
    
    magicSizeVector=[4 8 16 32];
    
    %largestDisplayedArray sets the
    %limit of array size that will be
    %inserted into the report with the
    %Insert Variable component.
    
    largestDisplayedArray=15;
  6. In the Evaluate this expression if there is an error text box, replace the existing text with the following text.

    disp(['Error during eval: ', lasterr])

    This causes an error to display if the M-code fails.

      Tip   To execute these commands immediately, click the Eval Now button at the top right corner of the Report Explorer. This is an easy way to check if your commands are correct, and ensure that they will not cause report-generation problems.

  7. Save the report by clicking File > Save.

Creating a Title Page

To create a title page for the report, use the Title Page component.

  1. In the Outline pane on the left, select the Eval component.

  2. In the Options pane in the middle, under the Formatting category, double-click Title Page to add the component to the report.

    Because the Eval component's icon indicates that this component cannot have children, the Title Page component is a sibling of the Eval component. Likewise, the Title Page component cannot have children either.

  3. In the Properties pane on the right,

    1. In the Title text box, enter Magic Squares.

    2. In the Subtitle text box, enter Columns, Rows, Diagonals: Everyone is Equal.

    3. Under Options, choose Custom author from the selection list.

    4. In the field to the right of the Custom author field, enter Albrecht Durer.

      Albrecht Dürer created the etching that contains a magic square. Your final report includes an image of that etching.

    5. Select the Include copyright holder and year check box.

    6. In the next text box, enter The MathWorks.

    7. In the second text box, enter 1998.

    8. Click the Abstract tab and then enter the following text:

      An introduction to Magic Squares and their meaning.

      The pane should look as follows:

  4. Save the report.

Adding the First Chapter

Add a chapter to the report by using the Chapter/Subsection component.

  1. In the Outline pane on the left, select the Title Page component.

  2. In the Options pane in the middle, under the Formatting category, double-click Chapter/Subsection.

    The Outline pane looks as follows.

    The Eval, Title Page, and Chapter components are all child components of the report's top level, but siblings of one another.

    The Chapter component can have child components. The next section explains how to add child components to this Chapter component.

  3. In the Properties pane on the right, enter Magic Squares Explained for the custom chapter title.

    The Outline pane on the left changes to reflect the chapter title.

  4. Save the report.

Adding Components to the First Chapter

Add introductory text to the first chapter using the Paragraph and Text components.

  1. In the Outline pane on the left, select the Chapter component.

  2. In the Options pane in the middle, under the Formatting category, double-click Paragraph.

    In the Outline pane on the left, the new component appears as a child of the Chapter component.

  3. By default, the Paragraph component inherits its text from its child components. Add two Text components.

      Note   The Text component must have the Paragraph component as its parent.

  4. In the Options pane in the middle, under the Formatting category, double-click Text.

  5. Double-click Text again to add a second component.

    The Outline pane looks as follows.

  6. In the Outline pane on the left, select the first Text component.

  7. In the Text to include in report text box, enter %<help('magic')>.

    The % sign and angle brackets <> indicate to the MATLAB Report Generator software that this is MATLAB code to evaluate. The command help('magic') displays information about the MATLAB magic function.

  8. In the Outline pane on the left, select the second Text component.

  9. In the Text to include in report text box, enter the following text.

      Tip   Copy and paste this text from the HTML documentation into the Report Explorer.

    The German artist Albrecht Durer (1471-1528) 
    created many woodcuts and prints with religious
    and scientific symbolism.  One of his most famous
    works, Melancholia I, explores the depressed state 
    of mind that opposes inspiration and expression.
    Renaissance astrologers believed that the Jupiter magic
    square (shown in the upper right portion of the image)
    could aid in the cure of melancholy. The engraving's 
    date (1514) can be found in the lower row of numbers
    in the square.  
  10. Save the report.

    The next step includes an image of the etching shown at the beginning of this section.

  11. In the Outline pane on the left, select the Chapter component.

  12. In the Options pane in the middle, under the MATLAB category, double-click Evaluate MATLAB Expression.

    The new component becomes a child of the Chapter component.

    Move the Eval component under the Paragraph component so that the image follows the introductory text.

  13. Click the down arrow on the toolbar to move the Eval component under the Paragraph component.

  14. With the Eval component still selected, do the following in the Properties pane on the right:

    1. Clear the Insert MATLAB expression in report and Display command window output in report check boxes. You do not want to include the code or its output in the report.

    2. In the Expression to evaluate in the base workspace text box, replace the existing text with the following M-code.

        Tip   Copy and paste this text from the HTML documentation into the Report Explorer.

      %This loads a self-portrait of Albrecht
      %Durer, a German artist. There is a
      %magic square in the upper right corner
      %of the image.
      
      durerData=load('durer.mat','-mat');
      figure('Units','Pixels',...
      'Position',[200 200 size(durerData.X,2)*.5 size(durerData.X,1)*.5 ]);
      
      image(durerData.X);
      colormap(durerData.map);
      axis('image');
      set(gca,...
          'Xtick',[],...
          'Ytick',[],...
          'Units','normal',...
          'Position',[0 0 1 1]);
      
      clear durerData

      This M-code displays the Dürer etching in a MATLAB figure window.

    3. In the Evaluate expression if there is an error text box, replace the existing text with the following text:

      disp(['Error during eval: ', lasterr])

      This code executes if an error occurs while loading the Dürer etching.

      The Properties pane on the right looks as follows.

    Now that the image of the Dürer etching appears in the MATLAB workspace, include it in the report using the Figure Snapshot component.

  15. In the Outline pane on the left, select the Eval component.

  16. In the Options pane in the middle, under the Handle Graphics category, double-click Figure Snapshot.

  17. In the Properties pane on the right:

    1. In the Paper orientation list, select Portrait.

    2. In the Invert hardcopy list, select Don't invert.

      Selecting this option specifies not to change the image's on-screen colors for printing.

    Delete the image after adding it to the report.

  18. In the Outline pane on the left, select the Figure Snapshot component.

  19. In the Options pane in the middle, under the MATLAB category, double-click Evaluate MATLAB Expression.

  20. In the Properties pane on the right:

    1. Clear the Insert MATLAB expression in report and Display command window output in report check boxes. You do not want to include the code or its output in the report.

    2. In the Expression to evaluate in the base workspace text box, replace the existing text with the following text:

      %This command deletes the Durer image
      delete(gcf);

      The delete(gcf) command deletes the current image in the MATLAB workspace, in this case, the Dürer etching.

    3. In the Evaluate expression if there is an error text box, replace the existing text with the following text:

      disp(['Error during eval: ', lasterr])

      This code executes if an error occurs while deleting the Dürer etching.

  21. Save the report.

The contents of the first chapter are now complete.

Creating the Magic Squares and Their Images

Use components to create several magic squares and insert the contents of the squares, or representative images, into the report.

Creating the For Loop

Each square has its own chapter. A For Loop component performs tasks for each square.

  1. In the Outline pane on the left, select the Chapter component.

  2. In the Options pane in the middle, under the Logical and Flow Control category, double-click For Loop.

    The Outline pane on the left looks as follows.

    This component appears inside the Chapter component. However, the magic squares should be processed after the first chapter, so the for component should be a sibling of the Chapter component, not a child.

  3. In the Outline pane on the left, select the for component.

  4. Click the left arrow to make the for component a sibling, not a child, of the Chapter component.

  5. In the Properties pane on the right:

    1. In the End text box, replace the existing text with the following text:

      length(magicSizeVector)

      This is the length of the vector that contains the various sizes for the magic square matrices.

    2. In the Variable name text box, replace the existing text with the following text:

      MAGIC_SQUARE_INDEX

      This variable acts as a loop index.

    The Outline pane on the left looks as follows.

  6. Save the report.

Adding a Chapter for Each Square

Add a chapter for each square processed using the Chapter/Subsection component.

  1. In the Outline pane on the left, select the for component.

  2. In the Options pane in the middle, under the Formatting category, double-click Chapter/Subsection.

    It becomes a child of the for component.

  3. In the Properties pane on the right, select Custom from the Title list and enter the following for the chapter title:

    Magic Square # %<MAGIC_SQUARE_INDEX>

    The Properties pane looks as follows.

  4. Save the report.

Determining the Matrix Size

Extract the size of each magic square matrix from magicSizeVector using an Evaluate MATLAB Expression component.

  1. In the Outline pane on the left, select the Chapter component.

  2. In the Options pane in the middle, under the MATLAB category, double-click Evaluate MATLAB Expression.

  3. In the Properties pane on the right:

    1. Clear the Insert MATLAB expression in report and Display command window output in report check boxes.

    2. In the Expression to evaluate in the base workspace text box, replace the existing text with the following text:

      magic_Square_Size=magicSizeVector(MAGIC_SQUARE_INDEX);

      This command extracts the next size for the magic square from the vector of sizes initialized in the first Eval component of the report. The variable magic_Square_Size represents the size of the current magic square being processed.

    3. In the Evaluate expression if there is an error text box, replace the existing text with the following:

      disp(['Error during eval: ', lasterr])

      This code executes if an error occurs while attempting to extract a value from magicSizeVector.

    The Outline pane on the left looks as follows.

  4. Save the report.

Inserting the Magic Square Size into the Report

Insert the size of the magic square into the report using the Paragraph and Insert Variable components.

  1. In the Outline pane on the left, select the Eval component.

  2. In the Options pane in the middle, under the Formatting category, double-click Paragraph.

    Do not change the properties. The variable that contains the size of the magic square goes in this paragraph.

  3. In the Outline pane on the left, select the Paragraph component.

  4. In the Options pane in the middle, under the MATLAB category, double-click Insert Variable.

  5. In the Properties pane on the right:

    1. In the Variable name text box, enter magic_Square_Size.

    2. In the Display as list, select Inline text.

    The Outline pane on the left looks as follows.

  6. Save the report.

Displaying the Magic Square

To create the magic square and display the associated matrix or image, use the Evaluate MATLAB Expression component.

  1. In the Outline pane on the left, select the Paragraph component.

  2. In the Options pane in the middle, under the MATLAB category, double-click Evaluate MATLAB Expression.

    Make this component a sibling of the Paragraph component, not a child.

  3. In the Outline pane on the left, select the Eval component.

  4. Click the left arrow on the toolbar to make the Eval component a sibling of the previous Paragraph component.

  5. In the Properties pane on the right:

    1. Clear the Insert MATLAB expression in report and Display command window output in report check boxes.

    2. In the Expression to evaluate in the base workspace text box, replace the existing text with the following M-code.

        Tip   Copy and paste this text from the HTML documentation into the Report Explorer.

      %This m-script produces a magic
      %square of size magic_Square_Size
      %and creates an image of that square.
      
      mySquare=magic(magic_Square_Size);
      clf
      imagesc(mySquare);
      title(sprintf('Magic Square N=%i',magic_Square_Size))
      set(gca,'Ydir','normal');
      axis equal;
      axis tight;
      

      This code creates a magic square matrix mySquare of size magic_Square_Size, and opens an image of that matrix in the MATLAB figure window.

    3. In the Evaluate expression if there is an error text box, replace the existing text with the following:

      disp(['Error during eval: ', lasterr])

      This code executes if an error occurs while creating and displaying the magic square.

    The Properties pane on the right looks as follows.

  6. Save the report.

  7. In the Outline pane on the left, select the Eval component.

  8. On the Options pane in the middle, under the Logical and Flow Control category, double-click Logical If.

  9. On the Properties pane on the right, in the Test Expression text box, replace the existing text with the following text:

    magic_Square_Size<=largestDisplayedArray

    This command tests if the current matrix size (magic_Square_Size) is less than or equal to the value assigned in the first Eval component of the report (largestDisplayedArray=15).

    To process the result of this Logical If component, create two child components—Logical Then and Logical Else. If magic_Square_Size is less than or equal to 15, the matrix variable appears in the report. If magic_Square_Size is greater than 15, the matrix image appears in the report.

  10. On the Outline pane on the left, select the if component.

  11. On the Options pane in the middle, under Logical and Flow Control, double-click Logical Else.

  12. On the Outline pane on the left, select the if component again.

  13. On the Options pane in the middle, under Logical and Flow Control, double-click Logical Then.

    The then component appears above the else component.

  14. In the Outline pane on the left, select the then component.

  15. In the Options pane in the middle, under the MATLAB category, double-click Insert Variable.

  16. In the Properties pane on the right:

    1. In the Variable name text box, enter mySquare, which is the variable that contains the magic square of the specified size.

    2. In the Title list, select None.

    3. In the Size Limit text box, enter 0.

      The Properties pane on the right looks as follows.

    This Variable component displays the magic square matrix, stored in the variable mySquare.

  17. In the Outline pane on the left, select the else component.

  18. In the Options pane in the middle, under the Handle Graphics category, double-click Figure Loop.

    Do not change its properties.

  19. In the Outline pane on the left, select the Figure Loop component.

  20. In the Options pane in the middle, under the Handle Graphics category, double-click Figure Snapshot.

  21. In the Properties pane on the right:

    1. In the Paper orientation list, select Portrait.

    2. In the Image size list, select Custom.

    3. Under the Image size list, enter [5 4] for the custom image size.

    4. In the Invert hardcopy list, select Invert.

      This option changes dark axes colors to light axes colors, and vice versa.

      The Properties pane on the right looks as follows.

    The Outline pane on the left looks like the following.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS