MATLAB Function Reports
When you simulate, update, or generate code from a Simulink® model that contains MATLAB Function blocks or Stateflow® charts with MATLAB® functions, Simulink generates a report for each MATLAB function in your model. The report provides type information for the variables and expressions in your functions, which can help you find the sources of errors and warnings.
Stateflow produces one report for each Stateflow chart, regardless of the number of MATLAB functions it contains.
If you have identical MATLAB Function blocks in your model, a single report is generated for the identical blocks.
Open a MATLAB Function Report
To open a MATLAB function report, use one of these methods:
Open the MATLAB function. On the Function tab, click Function Report.
Simulate or update the model. If a compilation error occurs, in the Diagnostic Viewer window, select the
For MATLAB Function blocks, call the
openReportfunction on the
MATLABFunctionConfigurationobject associated with the block. For more information, see Programmatically Access MATLAB Function Reports.
The first time that you open the MATLAB function report, Simulink automatically updates your model. If you make subsequent changes to the MATLAB code in the block, you must update your model before you reopen the report. Otherwise, the report does not reflect your changes. From the Modeling tab, select Update Model, or press Ctrl+D. For more information, see Update Diagram and Run Simulation.
Analyze MATLAB Source Code
In the MATLAB Source pane, the Function List view organizes functions by the file that contains them. To visualize functions according to the call structure, use the Call Tree view.
The MATLAB function report is read-only. To edit a function, select the name of the function in the MATLAB Source pane and click Open in Editor.
To view a MATLAB function in the code pane, click the name of the function in the MATLAB Source pane. In the code pane, when you pause on a variable or expression, a tooltip displays information about its size, type, and complexity. Additionally, syntax highlighting helps you to identify MATLAB syntax elements and certain code generation attributes, such as whether a function is extrinsic or whether an argument is constant.
The report identifies an extrinsic function with purple text. The tooltip indicates that the function is extrinsic.
Orange text indicates a compile-time constant argument to an entry-point function or a specialized function. The tooltip includes the constant value.
Knowing the value of a constant argument helps you to understand the generated function signatures. It also helps you to see when code generation creates function specializations for different constant argument values.
To export the value to a variable in the workspace, click the Export icon .
View Error and Warning Messages
To view errors and warnings, in the bottom pane of the report, open the All Messages tab. To highlight the source code for an error or warning, click the message. It is a best practice to address the first message in the list because subsequent errors and warnings are often related to the first message.
View MATLAB Variables
To view information about the variables for the selected MATLAB function, in the bottom pane of the report, open the Variables tab.
The variables table shows:
Class, size, and complexity
Properties of fixed-point types
This information helps you to understand type propagation and identify type mismatch errors.
Visual Indicators on the Variables Tab
This table describes the symbols, badges, and other indicators in the variables table.
|Column in the Variables Table||Indicator||Description|
|Name||expander||Variable has elements or properties that you can see by clicking the expander.|
|Name||Homogenous cell array (all elements have the same properties).|
|Size||Variable-size array with an upper bound of
|Size||Variable-size array with no upper bound.|
|Size||italics||Variable-size array whose dimensions do not change size during execution.|
To see the fixed-point properties, click the badge.
Programmatically Access MATLAB Function Reports
You can access MATLAB function reports by calling these functions on
openReportopens the MATLAB function report for the block.
closeReportcloses the MATLAB function report for the block.
MATLABFunctionReportobject for the block. You can query report information from this object by accessing its
Functionsproperty, which is an array of
coder.Functionobjects. See coder.Function Properties (MATLAB Coder).
For example, to create a custom report that lists the functions and variables
in the MATLAB Function block in the model
call_stats_block2 described in Create Custom Functionality Using MATLAB Function Blocks,
follow these steps:
MATLABFunctionConfigurationobject for the MATLAB Function block.
config = get_param('call_stats_block2/MATLAB Function', ... 'MATLABFunctionConfiguration');
MATLABFunctionReportobject for the MATLAB Function block.
report = getReport(config);
coder.Functionobjects in the report.
functions = report.Functions;
Create the custom report.
for i = 1:numel(functions) fprintf('Function %s uses these variables:\n',functions(i).Name) variables = functions(i).Variables; for j = 1:numel(variables) fprintf('%d. %s -- %s\n',j,variables(j).Name,variables(j).Scope) end fprintf('\n') end
Function stats uses these variables: 1. mean -- Output 2. stdev -- Output 3. vals -- Input 4. len -- Local Function avg uses these variables: 1. mean -- Output 2. array -- Input 3. size -- Input
MATLABFunctionReport object does not contain information about
errors and warnings. To find errors and warnings in a MATLAB Function
block, open the report or use the debugger in the MATLAB Function Block
Editor. For more information, see Locate and Fix Errors and
Debug MATLAB Function Blocks.