Documentation

coder.screener

Determine if function is suitable for code generation

Syntax

coder.screener(fcn)
coder.screener(fcn_1,...,fcn_n )

Description

coder.screener(fcn) analyzes the entry-point MATLAB® function, fcn. It identifies unsupported functions and language features, such as recursion and nested functions, as code generation compliance issues. It displays the code generation compliance issues in a report. If fcn calls other functions directly or indirectly that are not MathWorks® functions, coder.screener analyzes these functions. It does not analyze MathWorks functions. It is possible that coder.screener does not detect all code generation issues. Under certain circumstances, it is is possible that coder.screener reports false errors.

coder.screener(fcn_1,...,fcn_n ) analyzes entry-point functions (fcn_1,...,fcn_n).

Input Arguments

fcn

Name of entry-point MATLAB function that you want to analyze.

fcn_1,...,fcn_n

Comma-separated list of names of entry-point MATLAB functions that you want to analyze.

Examples

collapse all

Identify Unsupported Functions

The coder.screener function identifies calls to functions that are not supported for code generation. It checks both the entry-point function, foo1, and the function foo2 that foo1 calls.

Analyze the MATLAB function foo1 that calls foo2. Put foo1 and foo2 in separate files.

function out = foo1(in)
  out = foo2(in);
  disp(out);
end
function out = foo2(in)
  out = eval(in);
end
coder.screener('foo1')

The code generation readiness report displays a summary of the unsupported MATLAB function calls. The function foo2 calls one unsupported MATLAB function.

In the report, click the Code Structure tab and select the Show MATLAB functions check box.

This tab displays a pie chart showing the relative size of each file and how suitable each file is for code generation. In this case, the report:

  • Colors foo1.m green to indicate that it is suitable for code generation.

  • Colors foo2.m yellow to indicate that it requires significant changes.

  • Assigns foo1.m a code generation readiness score of 4 and foo2.m a score of 3. The score is based on a scale of 1–5. 1 indicates that significant changes are required; 5 indicates that the code generation readiness tool does not detect issues.

  • Displays a call tree.

The report Summary tab indicates that foo2.m contains one call to the eval function which code generation does not support. To generate a MEX function for foo2.m, modify the code to make the call to eval extrinsic.

function out = foo2(in)
  coder.extrinsic('eval');
  out = eval(in);
end

Rerun the code generation readiness tool.

coder.screener('foo1')

The report no longer flags that code generation does not support the eval function. When you generate a MEX function for foo1, the code generation software dispatches eval to MATLAB for execution. For standalone code generation, it does not generate code for it.

Identify Unsupported Data Types

The coder.screener function identifies data types that code generation does not support.

Analyze the MATLAB function foo3 that uses unsupported data types.

function [outSparse,outCategorical] = foo3(A,B,C)
    outSparse = sparse(A);
    outCategorical = categorical(B);
    outTable = table(C);
end
coder.screener('foo3')

The code generation readiness report displays a summary of the unsupported data types.

The report assigns the code a code readiness score of 2. This score indicates that the code requires extensive changes.

Before generating code, you must fix the reported issues.

Determine Code Generation Readiness for Multiple Entry-Point Functions

The coder.screener function identifies calls to functions that code generation does not support. It checks the entry-point functions foo4 and foo5.

Analyze the MATLAB functions foo4 and foo5.

function out = foo4(in)
  out = in;
  disp(out);
end
function out = foo5(in)
  out = eval(in);
end
coder.screener('foo4', 'foo5')

The code generation readiness report displays a summary of the unsupported MATLAB function calls. The function foo5 calls one unsupported MATLAB function.

In the report, click the Code Structure tab. Select the Show MATLAB functions check box.

This tab displays a pie chart showing the relative size of each file and how suitable each file is for code generation. In this case, the report:

  • Colors foo4.m green to indicate that it is suitable for code generation.

  • Colors foo5.m yellow to indicate that it requires significant changes.

  • Assigns foo4.m a code generation readiness score of 4 and foo5.m a score of 4. The score is based on a scale of 1–5. 1 indicates that significant changes are required; 5 indicates that the code generation readiness tool cannot detect issues.

  • Displays a call tree.

More About

collapse all

Tips

  • Before using coder.screener, fix issues that the Code Analyzer identifies.

  • Before generating code, use coder.screener to check that a function is suitable for code generation. Fix all the issues that it detects.

Introduced in R2012b

Was this topic helpful?