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. Use the report to debug your MATLAB functions and verify that they are suitable for code generation. The report provides type information for the variables and expressions in your functions, which can help you to find the sources of error messages and to understand type propagation rules.
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.
To open a MATLAB function report, use one of these methods:
Open the MATLAB function. In the Editor tab, click View Report.
Simulate or update the model. If a compilation error occurs, in the
Diagnostic Viewer window, select the report
link.
Call the openReport
function on the MATLABFunctionConfiguration
object for the block. For more information,
see Programmatically Access MATLAB Function Reports.
Note
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.
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 Edit in MATLAB.
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 .
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.
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 debug errors, such as type mismatch errors, and to understand type propagation.
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 | {:} | Heterogeneous cell array (all elements have the same properties). |
Name | {n} | n th element of a heterogeneous cell
array. |
Class | v > n | v is reused with a different class, size, and
complexity. The number n identifies a reuse with
a unique set of properties. When you pause on a renamed variable,
the report highlights only the instances of this variable that share
the class, size, and complexity. See Reuse the Same Variable with Different Properties. |
Size | :n | Variable-size array with an upper bound of
n . |
Size | :? | Variable-size array with no upper bound. |
Size | italics | Variable-size array whose dimensions do not change size during execution. |
Class | sparse prefix | Sparse array. |
Class | complex prefix | Complex number. |
Class | Fixed-point type. To see the fixed-point properties, click the badge. |
You can access MATLAB function reports by calling these functions on MATLABFunctionConfiguration
objects:
openReport
opens the MATLAB function report for the block.
closeReport
closes the MATLAB function report for the block.
getReport
returns a MATLABFunctionReport
object
for the block. You can query report information from this object by accessing its
Functions
property, which is an array of
coder.Function
objects. 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_block1
described in Create Custom Functionality Using MATLAB Function Block,
follow these steps:
Access the MATLABFunctionConfiguration
object for the
MATLAB Function block.
config = get_param('call_stats_block1/MATLAB Function', ... 'MATLABFunctionConfiguration');
Create the MATLABFunctionReport
object for the MATLAB
Function block.
report = getReport(config);
Access the coder.Function
objects 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
closeReport
| getReport
| MATLABFunctionConfiguration
| MATLABFunctionReport
| openReport