Main Content

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:


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.

Extrinsic Functions

The report identifies an extrinsic function with purple text. The tooltip indicates that the function is extrinsic.

Constant Arguments

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 TableIndicatorDescription
NameexpanderVariable has elements or properties that you can see by clicking the expander.
Name{:}Homogenous cell array (all elements have the same properties).
Name{n}nth element of a heterogeneous cell array.
Classv > nv 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:nVariable-size array with an upper bound of n.
Size:?Variable-size array with no upper bound.
SizeitalicsVariable-size array whose dimensions do not change size during execution.
Classsparse prefixSparse array.
Classcomplex prefixComplex number.

Fixed-point type.

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 MATLABFunctionConfiguration objects:

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:

  1. Access the MATLABFunctionConfiguration object for the MATLAB Function block.

    config = get_param('call_stats_block2/MATLAB Function', ...
  2. Create the MATLABFunctionReport object for the MATLAB Function block.

    report = getReport(config);
  3. Access the coder.Function objects in the report.

    functions = report.Functions;
  4. 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)
    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


The 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.

Report Limitations

  • The variables table does not show the individual elements of varargin and varargout.

  • The report does not show full information for unrolled loops. It displays data types of one arbitrary iteration.

  • The report does not show information about dead code.

See Also

| | | | |

Related Topics