Simulink Report Generator

Customizing a System Design Description Report: Part IV

This example shows you how to use Simulink® Report Generator™ to customize a System Design Description report for a model. The default version of the report provides information about a system design represented by a Simulink model. You can adapt the report to meet your needs.

This example shows you how to customize a report called System Design Description. The Simulink Report Generator product creates a default version of this report automatically from a Simulink model that you choose. However, you can generate a customized version of this report -- for example, to adhere to your organization's documentation standards.

This example assumes that you completed the previous customization described in "Customizing a System Design Description Report: Part III". In the previous example, you customized the System Design Description by adding new components to the report template. This example introduces you to a few more components. In particular, you will add components that simulate the model repeatedly, each time using new signals that produce different simulation results. You will capture all the results from multiple simulation runs for inclusion in the report.

You can customize the System Design Description for the Simulink example model, sldemo_autotrans, which represents an automotive drivetrain. To open the example model, run the following command:

open_system('sldemo_autotrans')

Open Report Explorer

From the Simulink model Tools menu, select Report Generator.

The Report Explorer graphical user interface opens.

Open the Custom Template in Report Explorer

In Report Explorer, open the custom template that you created in the previous example, "Customizing a System Design Description Report: Part III".

For your convenience, a version of the custom template is provided. To open the template in Report Explorer, run the following command:

setedit(fullfile(matlabroot, 'toolbox', 'rptgenext', 'rptgenextdemos', 'sdd', 'html', 'sdd_images', 'sdd_customize_part_iv', 'sdd_custom_simresults.rpt'))

Examine ManeuversGUI Block in Model

In the Simulink model sldemo_autotrans, double-click the ManeuversGUI Signal Builder block. This block produces two signals representing throttle and brake history, which other blocks in the model process to calculate engine and vehicle speed. In the Signal Builder dialog box, four different signal groups are present, each representing a different driving maneuver. In the dialog box, click a tab to activate the signals associated with a particular group. Simulate the model. Each group produces different simulation results.

In the previous example, "Customizing a System Design Description Report: Part III", you customized the System Design Description by adding a new chapter with results that the Scope block displays. This example shows you how to capture and include simulation results associated with each of the signal groups in the ManeuversGUI block.

Insert Evaluate MATLAB Expression Component

The number of signal groups in the Signal Builder block determines how many simulation runs are necessary to capture each set of results. MATLAB and Simulink functions enable you to compute this number automatically. During the report generation process use the Evaluate MATLAB Expression component to invoke those commands that compute the number of signal groups.

In the Report Explorer hierarchy pane, select the Chapter component that you added in the previous example to store the simulation results. From the list of components in the center pane, select the Evaluate MATLAB Expression component. In the right-hand pane, click the Add component to current report button.

Report Explorer inserts the Evaluate MATLAB Expression component as the first element of the chapter. In the hierarchy, select the new Eval component; in the Report Explorer properties pane, specify its Expression to evaluate in the base workspace property as follows:

  [t, y, labels, groups] = signalbuilder([gcs '/ManeuversGUI']);
  numGroups = length(groups);

Clear the Insert MATLAB expression in report check box so that the commands do not appear in your report.

Insert For Loop Component

The Evaluate MATLAB Expression component that you added in the previous step computes the variable numGroups, which specifies the number of simulation runs necessary to capture each set of results. You can use this variable in conjunction with a For Loop component to repeat tasks iteratively during the report generation process. In this case, the tasks to be repeated include simulating the model and taking a snapshot of the Scope block.

Add a For Loop component to the chapter that contains your simulation results. In the Report Explorer hierarchy pane, select the Evaluate MATLAB Expression component that you added previously. From the list of components in the center pane, select the For Loop component. In the right-hand pane, click the Add component to current report button.

Report Explorer inserts a new For Loop component after the Eval component in the chapter. Because the For Loop component executes only its child components iteratively, you must adjust the hierarchical position of components in this chapter. Use the arrow buttons in the Report Explorer toolbar to move the Paragraph, Model Simulation, and Scope Snapshot components in the hierarchy so that they are children of the For Loop component. The component hierarchy for this chapter should appear as follows:

In the hierarchy, select the For Loop component; in the Report Explorer properties pane, specify the component End property as %<numGroups>. (The %<...> notation enables you to reference the value of a variable from the base MATLAB workspace.) Also, change the Variable name property from the default value, RPTGEN_LOOP, to i.

Insert Another Evaluate MATLAB Expression Component

Previously, you added an Evaluate MATLAB Expression component to the chapter to determine the number of signal groups in the ManeuversGUI block. Insert another Evaluate MATLAB Expression component to invoke a Simulink function that changes the active signal group in the ManeuversGUI block.

In the Report Explorer hierarchy pane, select the For Loop component. From the list of components in the center pane, select the Evaluate MATLAB Expression component. In the right-hand pane, click the Add component to current report button.

Report Explorer inserts a new Evaluate MATLAB Expression component as the first child of the For Loop component in the chapter. In the hierarchy, select the new Eval component; in the Report Explorer properties pane, specify the component Expression to evaluate in the base workspace property as follows:

signalbuilder([gcs '/ManeuversGUI'], 'activegroup', i)

Clear the Insert MATLAB expression in report check box so that the command does not appear in your report. Also, clear the Display command window output in report check box so that additional, unwanted text does not appear in your report.

Edit Paragraph Component

The text of the paragraph that you added in the previous example does not provide a meaningful description of the throttle/brake history that the model uses to compute the simulation results. You can include a better description in your report. In the ManeuversGUI block, reference the signal group labels.

In the Report Explorer hierarchy, select the Paragraph component. Replace its Paragraph Text with the following:

Simulation Run %<i>: %<groups{i}>

The %<...> syntax enables you to reference the value of a variable from the base MATLAB workspace. The variable i represents the iterator associated with the For Loop component. Also, we reference and index into the variable groups, which the first Evaluate MATLAB Expression component generates.

Generate the Report

In the Report Explorer toolbar, click the Report button. When the report is complete, an application associated with the specified report format displays the customized System Design Description. The last chapter contains multiple simulation results from the different signal groups in the ManeuversGUI block.

Save the Template

From the Report Explorer File menu, select Save As. Specify a location and a file name for your custom report template. By saving a custom template, you can access and reuse it. For instance, you can apply the custom template to other Simulink models to create reports that have the same structure and format.

Further Information

To learn more about the properties of the components that you use in this portion of the example, refer to the Evaluate MATLAB ExpressionEvaluate MATLAB Expression and For LoopFor Loop reference pages in the MATLAB Report Generator documentation. For more information about the Signal Builder block, see its reference pagereference page in the Simulink documentation.