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
matlab\toolbox\shared\slreportgen\rpt\rpt\+slreportgen\ +report\@<reporter>\resources\templates\<output>
DiagramReporter
for PDF
output is
matlab\toolbox\shared\slreportgen\rpt\rpt\+slreportgen\ +report\@DiagramReporter\resources\templates\pdf\default.pdftx
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
slreportgen.report.Report
to hold the report.
Finder and Result Classes
Report API Class | Description |
---|---|
slreportgen.finder.AnnotationFinder | Finds Simulink block diagram annotations. |
slreportgen.finder.BlockFinder | Finds blocks in a Simulink block diagram. |
slreportgen.finder.BlockResult | Contains a block found by a BlockFinder
object. |
slreportgen.finder.ChartDiagramFinder | Finds Stateflow charts in a model. |
slreportgen.finder.DataDictionaryFinder | Finds Simulink data dictionaries. |
slreportgen.finder.DataDictionaryResult | Contains a data dictionary found by a
DataDictionary object. |
slreportgen.finder.DiagramElementFinder | Finds elements of a Simulink block diagram or Stateflow chart. |
slreportgen.finder.DiagramElementResult | Contains a diagram element found by a
DiagramElementFinder object. |
slreportgen.finder.DiagramFinder | Finds block diagrams and charts in a Simulink model. |
slreportgen.finder.DiagramResult | Contains a diagram found by a DiagramFinder
object. |
slreportgen.finder.ModelVariableFinder | Finds variables used by a Simulink model. |
slreportgen.finder.ModelVariableResult | Contains a model variable found by a
ModelVariableFinder object. |
slreportgen.finder.SignalFinder | Finds signals used by a model or block. |
slreportgen.finder.SignalResult | Contains a signal found by a SignalFinder
object. |
slreportgen.finder.StateFinder | Finds states in a Stateflow chart. |
slreportgen.finder.StateflowDiagramElementFinder | Finds elements of a Stateflow chart. |
slreportgen.finder.SystemDiagramFinder | Finds system block diagrams in a Simulink model. |
Reporter Classes
Report API Class | Description |
---|---|
slreportgen.report.Bus | Reports on buses selected or created by Simulink blocks. |
slreportgen.report.BusObject | Reports on Simulink.Bus
objects used by a model. |
slgreportgen.report.CCaller | Reports on a C Caller block. |
slreportgen.report.CFunction | Reports on a C Function block. |
slreportgen.report.DataDictionary | Reports on a Simulink data dictionary. |
slreportgen.report.Diagram | Creates a snapshot of a Simulink block diagram or a Stateflow chart. |
slreportgen.report.DocBlock | Reports on a Simulink DocBlock. |
slreportgen.report.ElementDiagram | Reports on an element diagram snapshot and caption. |
slreportgen.report.ExecutionOrder | Reports on the tasks of a model or nonvirtual subsystem and the blocks in each task, sorted by execution order. |
slreportgen.report.LookupTable | Reports on breakpoints and output points of a Simulink lookup table block. |
slreportgen.report.MATLABFunction | Reports on a |
slreportgen.report.ModelConfiguration | Reports on the active configuration set of a model. |
slreportgen.report.ModelVariable | Reports on a model variable. |
slreportgen.report.Notes | Reports on Simulink or Stateflow diagram notes. |
slreportgen.report.Signal | Reports on a signal. |
slreportgen.report.SimulinkObjectProperties | Creates a table of the properties of a Simulink object. |
slreportgen.report.StateflowObjectProperties | Creates a table of the properties of a Stateflow object. |
slreportgen.report.SystemHierarchy | Creates a nested list of the subsystems of a Simulink model or subsystem. |
slreportgen.report.SystemIO | Reports on Simulink system input and output signals. |
slreportgen.report.TestSequence | Reports on a Simulink Test Sequence block. |
slreportgen.report.TruthTable | Reports 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.
Run the following command to access the supporting files used in this example.
openExample('rptgenext/SimulinkReportGeneratorFilesExample');
Import the Report API package, which let you use class names without including their package names. For example, you can use
BlockFinder
instead ofslreportgen.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.* import slreportgen.report.* import mlreportgen.report.*
Load the
slrgex_vdp
model.model_name = 'slrgex_vdp'; load_system(model_name)
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 = slreportgen.report.Report('slrgex_vdp_model','html'); open(rpt)
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, theBlockFinder
finds all the blocks in the model. Use thefind
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); append(sect,result) append(ch,sect) end append(rpt,ch);
Close the report and model, and view the report.
close(rpt); close_system(model_name); rptview(rpt);
The full program is
import slreportgen.finder.* import slreportgen.report.* import mlreportgen.report.* model_name = 'slrgex_vdp'; load_system(model_name); rpt = slreportgen.report.Report('slrgex_vdp_model','html'); open(rpt) ch = Chapter('Blocks in slrgex_vdp model'); finder = BlockFinder(model_name); results = find(finder); for result = results sect = Section('Title',result.Name); append(sect,result) append(ch,sect); end append(rpt,ch); close(rpt) close_system(model_name) rptview(rpt)
The chapter heading and the section headings and property tables of the first two blocks of the resulting report are shown.
Use Specific Finders and Reporters for Different Block Types
Create a PDF report generator that finds all blocks in the
slrgex_radar_eml
model.
Run the following command to access the supporting files used in this example.
openExample('rptgenext/SimulinkReportGeneratorFilesExample');
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.
blkfinder = BlockFinder(model_name); blks = find(blkfinder); if slreportgen.utils.isMATLABFunction(blks(i).Object) rptr = MATLABFunction(blks(i).Object); sec = Section(blks(i).Name); append(sec,rptr) append(ch,sec) else sec = Section(blks(i).Name); append(sec,blks(i)) append(ch,sec)
blkfinder = BlockFinder(model_name); blks = find(blkfinder);
The full program is
import slreportgen.report.* import slreportgen.finder.* import mlreportgen.report.* model_name = 'slrgex_radar_eml'; load_system(model_name) rpt = slreportgen.report.Report('radar','pdf'); open(rpt) 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); append(sec,rptr) append(ch,sec) else sec = Section(blks(i).Name); append(sec,blks(i)) append(ch,sec) end end append(rpt,ch) close(rpt) close_system(model_name) rptview(rpt)
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.
Run the following command to access the supporting files used in this example.
openExample('rptgenext/SimulinkReportGeneratorFilesExample');
This portion of the code uses a StateFinder
object and its
find
method to find and report on states in the chart. It loops
through the array of found states and adds each one to the chapter.
stFinder = StateFinder(subsys); states = find(stFinder); for state = states append(chapter,state) end append(rpt,chapter)
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... ("Container",subsys,"Types","transition"); transitions = find(trFinder); for transition = transitions rptr = transition.getReporter; rptr.PropertyTable.TableWidth = "3in"; append(chapter,rptr) end append(rpt,chapter)
The complete program is
import mlreportgen.report.* import slreportgen.report.* import slreportgen.finder.* model_name = "slrgex_fuelsys_fuel_rate_control"; load_system(model_name); subsys = "slrgex_fuelsys_fuel_rate_control/control_logic"; rpt = slreportgen.report.Report("output","pdf"); open(rpt) tp = TitlePage("Title",... "Control Logic Chart of slrgex_fuelsys_fuel_rate_control"); append(rpt,tp) append(rpt,TableOfContents); chapter = Chapter("Title","States"); stFinder = StateFinder(subsys); states = find(stFinder); for state = states append(chapter,state) end append(rpt,chapter) chapter = Chapter("Title","Transitions"); trFinder = StateflowDiagramElementFinder... ("Container",subsys,"Types","transition"); transitions = find(trFinder); for transition = transitions rptr = transition.getReporter; rptr.PropertyTable.TableWidth = "3in"; append(chapter,rptr) end append(rpt,chapter) close(rpt) close_system(model_name) rptview(rpt)