Main Content

Model Loop

Loop on Simulink models and systems, as specified by child components

Description

This component loops on Simulink® models and systems, as specified by child components. For example, you can use a Model Loop with a child System Loop to report on the subsystems of the specified system.

Consider making these components children of the Model Loop (although the Model Loop is not necessarily required to be the immediate parent of a given component).

For conditional processing based of blocks, you can use the RptgenSL.getReportedBlock function. For more information, see Loop Through Context Functions.

Models to Include

You can add a model to the list by clicking Add New Model to List. The following table shows the buttons you can use to move a model up or down in the list, or to add or delete a model.

Button

Action

Up arrow

Move a model up in the list.

Down arrow

Move a model down in the list.

Red X

Remove a model from the list.

Plus sign and model icon

Add a new model to the list.

Model Options

  • Active: Includes a given model in the loop. This option is selected by default. Clearing this option omits the model from the loop.

    This option allows you to temporarily omit one or more models from a report.

  • Model name: Specifies the model name.

    • Current block diagram

    • All open models

    • All open libraries

    • Block diagrams in current directory

    • Custom block diagram: Selecting this option automatically sets the Starting system(s) field $top to start in the model root system.

    • %<VariableName>: For more information, see %<VariableName> Notation on the Text component reference page in the MATLAB® Report Generator™ documentation.

  • Traverse model: Specifies the systems to traverse.

    • All systems in model

    • Selected system(s) only

    • Selected system(s) and ancestors

    • Selected system(s) and children

  • Look under masks: Specifies how to handle masks.

    • Functional masks only

    • No masks

    • All masks

    • Graphical masks only

    For more information, see Author Block Masks.

  • Follow library links: Specifies library links to include.

    • Do not follow library links: Library links are treated as blocks.

    • Include library links: Library links are treated as subsystems.

    • Include unique library links: With multiple copies of the same library link in a system, one is treated as a subsystem and the others as blocks.

    For more information, see Linked Blocks.

  • Model reference: Specifies whether to report on models referenced by a Model block. If you want to report on referenced models, then you can control the depth of the model hierarchy and whether to report on variant models.

    • Do not follow Model blocks: Do not report on blocks contained in referenced models.

    • Follow all Model blocks: Report on blocks contained in all models that any part of the model hierarchy references.

    • Follow Model blocks defined in current model: Report on blocks in models that the currently selected model references.

    • <Custom model reference depth>: Report on blocks in models that your specified level in the model hierarchy references.

  • Include all variants: Report on all variant models. To enable this option, set the Model reference option to report on blocks in referenced models.

  • Subsystem reference: Select this option to report on subsystem files referenced by a Subsystem Reference block.

  • Starting system(s): Specifies the system in which to start the loop. Available options depend on the value that you select in the Traverse model option. Selecting any option other than All systems in model for Traverse model activates the Starting system(s) option.

    If you do not enter a model name in the Model name option, then select either Root model or Current to specify where to start the loop.

    If you specify a model name in the Model name option, then the Starting system(s) option provides an edit box in which you can enter:

    • The full path of a subsystem or subsystems

    • $top to start the loop in the model root system

    • $current to start the loop in the currently selected system

Section Options

  • Create section for each object in loop: Inserts a section in the generated report for each object found in the loop.

  • Display the object type in the section title: Automatically inserts the object type into the section title in the generated report. This is only available when Create section for each object in loop is selected.

  • Create link anchor for each object in loop: Create a link target on each object in the loop so that other parts of the report can link to it.

Examples

Example 1. Generating Reports on Specified Systems and Their Subsystems

This example shows how to loop over a specified system and its subsystems in the sample model sldemo_auto_climate_elec.

  1. (Optional) To open the sldemo_auto_climate_elec model, at the MATLAB command prompt, enter the following command:

    openExample('sldemo_auto_climate_elec')

    Explore the model to familiarize yourself with its subsystems.

  2. Open the Report Explorer.

  3. Create a report setup file by clicking File > New.

  4. Save the report setup file by clicking File > Save As. Give it the name sldemo_auto_report.

  5. Add a Chapter/Subsection component to the report setup file to include information about model subsystems:

    1. In the Library pane in the middle, double-click Chapter/Subsection to add it to the report setup file.

    2. For Title, choose Custom. In the title field, enter Description of subsystems.

    3. Add a Model Loop as a child of the Chapter/Subsection component. This loops over the ClimateControlSystem system and its subsystems in the sldemo_auto_climate_elec model:

      1. In the Library pane in the middle, double-click Model Loop to add it to the report setup file. By default, the Report Explorer adds that component as a child of the Chapter/Subsection component.

      2. In the Model Loop properties pane, from the Model name selection list, select <Custom block diagram>.

      3. In the Model name field, delete the text <Custom block diagram>, and then enter sldemo_auto_climate_elec.slx. Click any component in the report setup file to add this model to the Models to include list.

      4. In the Traverse model selection list, select Selected system(s) and children.

      5. In the Look under masks selection list, select All masks.

      6. In the Model reference selection list, select Do not follow Model blocks.

      7. In the Starting system(s) field, enter sldemo_auto_climate_elec/ClimateControlSystem. Because you selected Selected system(s) and children for Traverse model, the Model Loop loops over sldemo_auto_climate_elec/ClimateControlSystem and its subsystems.

      8. Under Section Options, select the Create section for each object in loop check box. Selecting this option creates separate sections in the generated report for each model over which the component loops.

      The Model Loop properties pane looks as follows.

      Model Loop properties pane

  6. Save the report by clicking File > Save.

  7. Add a System Loop as a child of the Model Loop component.

    1. In the Library pane in the middle, double-click System Loop to add it to the report setup file. By default, Model Explorer adds this component as a child of the Model Loop component.

    2. In the System Loop properties pane, under Loop Options, select the Create section for each object in loop check box. Selecting this option creates a section in the generated report for each subsystem on which the component loops. Accept the default values for all other fields.

  8. Add a System Snapshot component as a child of the System Loop component. This step creates snapshots of all the subsystems of ClimateControlSystem in the generated report. In the Library pane in the middle, double-click System Snapshot. By default, Model Explorer adds this component as a child of the System Loop component.

  9. Save the report.

    The report setup file hierarchy now looks as follows.

    Report Explorer with System Snapshot component selected

  10. Run the report by clicking File > Report.

    The report loops on the system ClimateControlSystem of the sldemo_auto_climate_elec model and all of its subsystems, as shown in the following Message List.

    Message List with information about looping on model sldemo_auto_climate_elec and its subsystems

Below is an excerpt from the generated report.

Sample page showing Chapter 1 followed by a Table of Contents and a Simulink model displaying model sldemo_auto_climate_elec

Example 2. Temporarily Omitting a Model from a Loop

This example shows how to use the Model Loop Active check box to temporarily omit a model from the loop. This example uses the report setup file that you created in the Generating Reports on Specified Systems and their Subsystems example above, sldemo_auto_report.rpt, and the f14 Simulink model.

  1. (Optional) To open the f14 model, at the MATLAB command prompt, enter the following command:

    openExample('f14')

    Explore the model to familiarize yourself with its subsystems.

  2. In the Report Explorer, click File > Open, and then open sldemo_auto_report.rpt by double-clicking it.

  3. In the Outline pane on the left, click Model Loop Section 1 - sldemo_auto_climate_elec.

  4. In the Model Loop properties pane, click the button to add a model to the Models to include list.

  5. In the Model Loop properties pane, from the Model name selection list, select <Custom block diagram>.

  6. In the Model name field, delete the text <Custom block diagram> and enter 14.slx.

  7. In the Look under masks selection list, select All masks.

    The Model Loop properties pane now looks as follows.

    Model Loop properties pane displaying model options

  8. Save the report setup file.

  9. Generate the report.

    The report generation process loops over the specified systems in the f14 and sldemo_auto_climate_elec models, as shown in the following message box.

    Message List with information about looping on models f14 and sldemo_auto_climate_elec and their subsystems

    Below is an excerpt from the generated report.

    Sample report page showing Chapter 1 followed by a Table of Contents and a Simulink model displaying model f14

  10. In the Models to include list, click f14 to select it.

  11. Clear the Active check box to omit f14 model information from the generated report.

  12. Rerun the report.

    The report now includes information only on the sldemo_auto_climate_elec model, as shown at the end of the previous example, Generating Reports on Specified Systems and their Subsystems.

  13. To reactivate the f14 model, in the Model Loop Models to include list, select the f14 model and then select the Active check box.

Insert Anything into Report?

Yes, inserts a section if you select Create section for each object in loop and a link target if you select Create link anchor for each object in loop.

Class

rptgen_sl.csl_mdl_loop