Documentation

MATLAB Function Reports

About MATLAB Function Reports

When you build a Simulink® model that contains MATLAB Function blocks, Simulink generates a report in HTML format for each MATLAB Function block in your model. You can use the report to debug your MATLAB® functions and verify that they are suitable for code generation. The report provides links to your MATLAB functions and compile-time type information for the variables and expressions in these functions. If your model fails to build, this information simplifies finding sources of error messages and aids understanding of type propagation rules.

    Note:   If you have a Stateflow® license, there is one report for each Stateflow chart, regardless of the number of MATLAB functions it contains.

    Note:   If you have identical MATLAB Function blocks in your model, for example, one in a library and one in the model, a single report is generated for the identical blocks.

Opening MATLAB Function Reports

Use one of the following methods:

  • In the MATLAB Function Block Editor, select View Report.

  • If compilation errors occur, in the Diagnostic Viewer window, select thereport link.

Description of MATLAB Function Reports

When you build the MATLAB function, the code generation software generates an HTML report. The report provides the following information, as applicable:

  • MATLAB code information, including a list of all functions and their compilation status

  • Call stack information, providing information on the nesting of function calls

  • Summary of compilation results, including type of target and number of warnings or errors

  • List of error and warning messages

  • List of variables in your MATLAB function

Viewing Your MATLAB Function Code

To view your MATLAB function code, click the MATLAB code tab. The report displays the MATLAB code for the function highlighted in the list on this tab.

The MATLAB code tab provides:

  • A list of the MATLAB functions that have been compiled. The report displays icons next to each function name to indicate whether compilation was successful:

    • Errors in function.

    • Warnings in function.

    • Successful compilation, no errors or warnings.

  • A filter control that you can use to sort your functions by:

    • Size

    • Complexity

    • Class

Viewing Local Functions

The report annotates the local function with the name of the parent function in the list of functions on the MATLAB code tab.

For example, if the MATLAB function fcn1 contains the local function subfcn and fcn2 contains the local function subfcn2, the report displays:

fcn1 > subfcn1
fcn2 > subfcn2

Viewing Specializations

If your MATLAB function calls the same function with different types of inputs, the report numbers each of these specializations in the list of functions on the MATLAB code tab.

For example, if the function fcn calls the function subfcn with different types of inputs:

function y = fcn(u) %#codegen
% Specializations
y = y + subfcn(single(u));
y = y + subfcn(double(u));
The report numbers the specializations in the list of functions.
fcn > subfcn > 1
fcn > subfcn > 2

Viewing Call Stack Information

The report provides call stack information:

  • On the Call stack tab.

  • In the list of Callers.

    If a function is called from more than one function, this list provides details of each call site. Otherwise, the list is disabled.

Viewing Call Stack Information on the Call Stack Tab

To view call stack information, click the Call stack tab. The call stack lists the functions in the order that the top-level function calls them. It also lists the local functions that each function calls.

Viewing Function Call Sites in the Callers List

If a function is called from more than one function, this list provides details of each call site. To navigate between call sites, select a call site from the Callers list. If the function is not called more than once, this list is disabled.

Viewing the Compilation Summary Information

To view a summary of the compilation results, including type of target and number of errors or warnings, click the Summary tab.

Viewing Error and Warning Messages

The report provides information about errors and warnings. If errors occur during simulation of a Simulink model, simulation stops. If warnings occur, but no errors, simulation of the model continues.

The report provides information about warnings and errors by listing all errors and warnings in chronological order in the All Messages tab.

Viewing Errors and Warnings in the All Messages Tab

If errors or warnings occurred during compilation, click the All Messages tab to view a complete list of these messages. The report lists the messages in the order that the compiler detects them. It is best practice to address the first message in the list, because often subsequent errors and warnings are related to the first message.

To locate the offending line of code for an error or warning in the list, click the message in the list. The report highlights errors in the list and MATLAB code in red and warnings in orange. Click the blue line number next to the offending line of code in the MATLAB code pane to go to the error in the source file.

    Note:   You can fix errors only in the source file.

Viewing Error and Warning Information in Your MATLAB Code

If errors or warnings occurred during compilation, the report underlines them in your MATLAB code. The report underlines errors in red and warnings in orange. To learn more about a particular error or warning, place your pointer over the underlined text.

MATLAB Code Variables in a Report

The report provides compile-time type information for the variables and expressions in your MATLAB code, including name, type, size, complexity, and class. It also provides type information for fixed-point data types, including word length and fraction length. You can use this type information to find the sources of error messages and to understand type propagation rules.

You can view information about the variables in your MATLAB code:

  • On the Variables tab, view the list.

  • In your MATLAB code, place your cursor over the variable name.

    In the MATLAB code, an orange variable name indicates a compile-time constant argument to a specialized function. The information for a constant argument includes the value. This information helps you to see when code generation created function specializations for different constant argument values.

Variables on the Variables Tab

To view a list of the variables in your MATLAB function, click the Variables tab. The report displays a complete list of variables in the order that they appear in the function that you selected on the MATLAB code tab. Clicking a variable in the list highlights instances of that variable, and scrolls the MATLAB code pane so that you can view the first instance.

As applicable, the report provides the following information about each variable:

  • Order

  • Name

  • Type

  • Size

  • Complexity

  • Class

  • DataTypeMode (DT mode) — for fixed-point data types only. For more information, see Data Type and Scaling Properties.

  • Signed — sign information for built-in data types, signedness information for fixed-point data types.

  • Word length (WL) — for fixed-point data types only.

  • Fraction length (FL) — for fixed-point data types only.

The report displays a column only if at least one variable in the code has information in that column. For example, if the code does not contain fixed-point data types, the report does not display the DT mode, WL, or FL columns.

Sorting Variables on the Variables Tab.  By default, the report lists the variables in the order that they appear in the selected function.

To sort the variables, click the column headings on the Variables tab. To sort the variables by multiple columns, hold down the Shift key when you click the column headings.

To restore the list to the original order, click the Order column heading.

Structures on the Variables Tab.  To display structure field properties, expand the structure on the Variables tab.

If you sort the variables by type, size, complexity, or class, it is possible that a structure and its fields do not appear sequentially in the list. To restore the list to the original order, click the Order column heading.

Variable-Size Arrays in the Variables Tab.  For variable-size arrays, the Size field includes information about the computed maximum size of the array. The size of each array dimension that varies is prefixed with a colon :. The size of an unbounded dimension is :?.

In the following report, variables A and B are variable-size. The second dimension of A has a maximum size of 100. The size of the second dimension of B is :?.

If you declare a variable-size array, and then fix the dimensions of this array in the code, the report appends * to the size of the variable. In the generated C code, this variable appears as a variable-size array, but the sizes of its dimensions do not change during execution.

For information about how to use the size information for variable-size arrays, see Variable-Size Data Definition for Code Generation.

Renamed Variables in the Variables Tab.  If your MATLAB function reuses a variable with a different size, type, or complexity, the code generation software attempts to create separate, uniquely named variables. For more information, see Reuse the Same Variable with Different Properties. The report numbers the renamed variables in the list on the Variables tab. When you place your cursor over a renamed variable, the report highlights only the instances of this variable that share data type, size, and complexity.

For example, suppose that your code uses the variable t to hold a scalar double, and reuses it outside the for-loop to hold a vector of doubles. In the list on the Variables tab, the report displays two variables, t>1 and t>2,

Viewing Information About Variables and Expressions in Your MATLAB Function Code

To view information about a particular variable or expression in your MATLAB function code, on the MATLAB code pane, place your cursor over the variable name or expression. The report highlights variables and expressions in different colors:

Green, when the variable has data type information at this location in the code  

For variable-size arrays, the Size field includes information on the computed maximum size of the array. The size of each array dimension that varies is prefixed with a colon :.

Green with orange text, when a constant argument has data type and value information.  When the variable is a compile-time constant argument to a specialized function:

  • The variable name is orange.

  • The information for the variable includes the value.

If you export the value as a variable to the base workspace, you can use the Workspace browser to view detailed information about the variable.

To export the value to the base workspace:

  1. Click the Value link.

  2. In the Export Constant Value dialog box, specify the Variable name.

  3. Click OK.

    The variable and its value appear in the Workspace browser.

Pink, when the variable has no data type information  

Purple, information about expressions.  You can also view information about expressions in your MATLAB code. On the MATLAB code pane, place your cursor over an expression. The report highlights expressions in purple and provides more detailed information.

Red, when there is error information  

Keyboard Shortcuts for the MATLAB Function Report

You can use keyboard shortcuts settings to perform actions in the report.

This table lists actions that you can associate with a keyboard shortcut. The keyboard shortcuts are defined in your MATLAB preferences. See Define Keyboard Shortcuts.

ActionDefault Keyboard Shortcut for a Windows® Platform
Zoom inCtrl+Plus
Zoom outCtrl+Minus
Evaluate selected MATLAB codeF9
Open help for selected MATLAB codeF1
Open selected MATLAB codeCtrl+D
Step backward through files that you opened in the code paneAlt+Left
Step forward through files that you opened in the code paneAlt+Right
RefreshF5
SearchCtrl+F

Alternatively, you can select these actions from a context menu. To open the context menu, right-click anywhere in the report.

This table lists keyboard shortcuts that help you navigate between panes and tabs in the code generation report. To advance through data in the selected pane, use the Tab key. These keyboard shortcuts override the keyboard shortcut settings in your MATLAB preferences. See Define Keyboard Shortcuts.

To select Use
MATLAB code tabCtrl+M
Call stack tabCtrl+K
Code Pane Ctrl+W
Summary TabCtrl+S
All Messages TabCtrl+A
Variables TabCtrl+V

Searching in the MATLAB Function Report

Use the keyboard shortcut associated with Find in your MATLAB preferences. The default keyboard shortcut for Find on a Windows platform is Ctrl+F.

Report Limitations

The report displays information about the variables and expressions in your MATLAB code with the following limitations:

 varargin and varargout

 Loop Unrolling

 Dead Code

 Structures

 Column Headings on the Variables Tab

 Multiline Matrices

More About

Was this topic helpful?