Main Content

Create Report Generators for Simulink and Stateflow Elements

Finders and reporters reduce the amount of time and complexity required to write code to find and report on Simulink® model elements, such as diagrams and blocks, and on Stateflow® charts and transitions, etc. The Simulink Report Generator™ Report API is a layer on top of the DOM API. Its finders and reporters are based on the Simulink and Stateflow find base class. You specify the container in which to find specific elements, such as blocks in a subsystem or states in a chart. Finder objects return their results in a corresponding array of finder result objects.

The Simulink Report API also includes reporter classes, which return an image of the container. This image is the top level of a model.

Every result object returned by a finder has an associated reporter object, which reports on those results. The reporter object holds the content and formats the content, such as tables of properties and data plots. You add the reporter objects to your reports. Use the MATLAB® Report API reporters to define common report elements. See What Are Reporters? for information.

All finders and reporters have these features:

  • Default behaviors and values

  • Allow overriding and customizing their output

All finders have find, hasNext, and next methods. The find method finds and returns in an array of result objects all elements for each found element of the specified type. The hasNext and next methods find and return one element at a time and are used to iterate over a list of results. The hasNext method checks whether the container has at least one of the element of the specified type. If the container has one or more of the elements, then the hasNext method queues it for the next method to find and return as a result object.

All reporters have predefined templates. The template for each reporter defines its formatting, layout, and content holes. You do not need to change the template or specify any formats, layouts, or holes unless you want a customized report. You can customize your report by copying and editing its default template or by using a new template. Editing a copy of the default template gives you a starting point and structure to follow to customize your template. Using a new template lets you completely define your template starting with a blank file. To change the order of the report content, reorder the holes in the template. Finders do not use templates. Another way to customize a reporter class is by subclassing it.

The default reporter templates for each output type are in a template library, which is at

For example, the path to the default template for the DiagramReporter for PDF output is
For a detailed example of editing a template, see the "Reporter Elements" section of What Are Reporters?

Simulink Report API Classes

The Simulink Report API provides these finder, result, and reporter classes. To use these classes in a report generator program, you must create a container of type to hold the report.

Finder and Result Classes

Report API ClassDescription
slreportgen.finder.AnnotationFinderFinds Simulink block diagram annotations.
slreportgen.finder.BlockFinderFinds blocks in a Simulink block diagram.
slreportgen.finder.BlockResultContains a block found by a BlockFinder object.
slreportgen.finder.ChartDiagramFinderFinds Stateflow charts in a model.
slreportgen.finder.DataDictionaryFinderFinds Simulink data dictionaries.
slreportgen.finder.DataDictionaryResultContains a data dictionary found by a DataDictionary object.
slreportgen.finder.DiagramElementFinderFinds elements of a Simulink block diagram or Stateflow chart.
slreportgen.finder.DiagramElementResultContains a diagram element found by a DiagramElementFinder object.
slreportgen.finder.DiagramFinderFinds block diagrams and charts in a Simulink model.
slreportgen.finder.DiagramResultContains a diagram found by a DiagramFinder object.
slreportgen.finder.ModelVariableFinderFinds variables used by a Simulink model.
slreportgen.finder.ModelVariableResultContains a model variable found by a ModelVariableFinder object.
slreportgen.finder.SignalFinderFinds signals used by a model or block.
slreportgen.finder.SignalResultContains a signal found by a SignalFinder object.
slreportgen.finder.StateFinderFinds states in a Stateflow chart.
slreportgen.finder.StateflowDiagramElementFinderFinds elements of a Stateflow chart.
slreportgen.finder.SystemDiagramFinderFinds system block diagrams in a Simulink model.

Reporter Classes

Report API ClassDescription on buses selected or created by Simulink blocks. on Simulink.Bus objects used by a model. on a C Caller block. on a C Function block. on a Simulink data dictionary. a snapshot of a Simulink block diagram or a Stateflow chart.

Reports on a Simulink DocBlock. on an element diagram snapshot and caption. on the tasks of a model or nonvirtual subsystem and the blocks in each task, sorted by execution order. on breakpoints and output points of a Simulink lookup table block.

Reports on a MATLAB Function block or a Stateflow MATLAB function. on the active configuration set of a model. on a model variable. on Simulink or Stateflow diagram notes. on a signal. a table of the properties of a Simulink object. a table of the properties of a Stateflow object. a nested list of the subsystems of a Simulink model or subsystem. on Simulink system input and output signals.

Reports on a Simulink Test Sequence block. on a Simulink truth table block or a Stateflow truth table object.

Find and Report on Blocks in a Model

This example shows how to find and report on all Simulink blocks in the slrgex_vdp model using the BlockFinder class. The resulting HTML report includes default information and uses default formatting for each block.

Import the Report API package, which let you use class names without including their package names. For example, you can use BlockFinder instead of slreportgen.finder.BlockFinder. In addition to importing the Simulink Report API base classes, import the MATLAB Report API base class. A typical report includes a title page, table of contents, chapters, and sections, which you include as reporter classes in the MATLAB Report API.

import slreportgen.finder.*

Load the slrgex_vdp model.

model_name = 'slrgex_vdp';

Create the container object to hold the report and open the report. In this case, the output report is saved in zipped slrgex_vdp_model.htmx HTML report. You can use any output name you want. If you run the report generator more than once using the same output file name, the output file is overwritten. To use Simulink Report API finders and reporters in your report generator program, you must use the fully qualified name to create the container object.

rpt ='slrgex_vdp_model','html');

Add a chapter and specify its title.

ch = Chapter('Blocks in slrgex_vdp model');

Use the BlockFinder class to create a finder. In this case, the BlockFinder finds all the blocks in the model. Use the find method to find the blocks specified by the finder.

finder = BlockFinder(model_name); 
results = find(finder);

Loop through the results of the find method and create a section for each block, and add the block property table to the section. Then, add each section to the chapter. After all blocks have been added, add the chapter to the report.

for result = results
     sect = Section('Title',result.Name);

Close the report and model, and view the report.


Use Specific Finders and Reporters for Different Block Types

Create a PDF report generator that finds all blocks in the slrgex_radar_eml model.

To find all blocks, use the BlockFinder. The if statement shows how to test for MATLAB Function blocks. Use the MATLABFunction reporter to report MATLAB Function block details. The else statement shows how blocks other than MATLAB Function blocks use the BlockFinder find method results.

import slreportgen.finder.*

model_name = 'slrgex_radar_eml';

rpt ='radar','pdf');

blkfinder = BlockFinder(model_name);
blks = find(blkfinder);
ch = Chapter('Blocks in slrgex_radar_eml Model');

for i=1:length(blks)
   if slreportgen.utils.isMATLABFunction(blks(i).Object)
      rptr = MATLABFunction(blks(i).Object);
      sec = Section(blks(i).Name);
      sec = Section(blks(i).Name);


An example of the information reported for a MATLAB Function block by the MATLABFunction reporter is:


An example of the information reported by the find method of the BlockFinder is:


Find and Report on Stateflow Elements

This example describes how to find and report on Stateflow states, transitions, and junctions. It reports on the control_logic chart of the slrgex_fuelsys_fuel_rate_control model.

First, set up the report.

import slreportgen.finder.*

model_name = "slrgex_fuelsys_fuel_rate_control";
subsys = "slrgex_fuelsys_fuel_rate_control/control_logic";

rpt ="output","pdf");

tp = TitlePage("Title",...
   "Control Logic Chart of slrgex_fuelsys_fuel_rate_control");

Next, use a StateFinder object and its find method to find and report on states in the chart. Loop through the array of found states and add each one to the chapter.

chapter = Chapter("Title","States");
stFinder = StateFinder(subsys);
states = find(stFinder);
for state = states


To report on the transitions, use a StateflowDiagramElementFinder object and its find method. To show the property table with a narrower width than the default, customize the output. First, obtain the reporter for the result. To set the width, use the TableWidth property of the reporter.

chapter = Chapter("Title","Transitions");
trFinder = StateflowDiagramElementFinder...
transitions = find(trFinder);
for transition = transitions
   rptr = transition.getReporter;
   rptr.PropertyTable.TableWidth = "3in"; 


Close the report and model, and view the report.


See Also

Related Topics