Use Fixed-Point Code Generation Reports

Code Generation Report Creation

When you compile your code with the fiaccel function or the MATLAB® Coder™ codegen function, you can use the -report option to generate a code generation report. This report allows you to examine the data types of the variables and expressions in your code.

This example shows how to create a code generation report.

  1. In a local writable folder, write a MATLAB function, moving_average.m.

    function [avg,z] = moving_average(x,z)
    %#codegen
      if nargin < 2,
        z = fi(zeros(10,1),1,16,15);
      end
      z(2:end) = z(1:end-1);  % Update buffer
      z(1) = x;	              	% Add new value
      avg = mean(z);          % Compute moving average
    end
  2. In the same folder, write a MATLAB function, test_moving_average.m.

    function avg = test_moving_average(x)
    %#codegen
      if nargin < 1,
        x = fi(rand(100,1),1,16,15);
      end
      z = fi(zeros(10,1),1,16,15);
      avg = x;
      for k = 1:length(x)
        [avg(k),z] = moving_average(x(k),z);
      end
    end
  3. Use fiaccel to create a MEX function and accelerate the code. Specify the type of input x using the -args option. Specify the -report option to create a code generation report.

    x = fi(rand(100,1),1,16,15);
    fiaccel -report test_moving_average -args {x} 

Code Generation Report Opening

If code generation completes, you receive the following message:

Code generation successful: View report

Click the View report link to open the report.

If code generation fails, you get a link to the error report:

Code generation failed: View report

Click the View report link to view the error report and debug your code. For more information on working with error reports, see Code Generation Reports.

Viewing Your MATLAB Code

When the code generation report opens, you can hover your cursor over the variables and expressions in your MATLAB code to see their data type information. The code generation report provides color-coded data type information according to the following legend.

ColorMeaning
GreenData type information is available for the selected variable at this location in the code.
OrangeThere is a warning message associated with the selected variable or expression.
PinkNo data type information is available for the selected variable.
PurpleData type information is available for the selected expression at this location in the code.
RedThere is an error message associated with the selected variable or expression.

Variables in your code that have data type information available appear highlighted in green.

Expressions in your code that have data type information available appear highlighted in purple, as the next figure shows.

Viewing Variables in the Variables Tab

To see the data type information for all the variables in your file, click the Variables tab of the code generation report. You can expand all fi and fimath objects listed in the Variables tab to display the fimath properties. When you expand a fi object in the Variables tab, the report indicates whether the fi object has a local fimath object or is using default fimath values.

The following figure shows the information displayed for a fi object that is using default fimath values.

You can sort the variables by clicking the column headings in the Variables tab. To sort the variables by multiple columns, press the Shift key while clicking the column headings.

See Also

For more information about using the code generation report with the fiaccel function, see the fiaccel reference page.

For information about local and default fimath, see fimath Object Construction.

For information about using the code generation report with the codegen function, see Code Generation Reports.

Was this topic helpful?