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, cell arrays, nested functions, and function handles as code generation compliance issues and displays them in a report. If fcn calls other functions directly or indirectly that are not MathWorks® functions, coder.screener analyzes these functions too. It does not analyze MathWorks functions. coder.screener might not detect all code generation issues. Under certain circumstances, it might report 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

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

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 opens. It provides 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 Show MATLAB functions.

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 some significant changes are required.

  • 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 to 5. 1 indicates that significant changes are required; 5 indicates that the code generation readiness tool cannot detect issues.

  • Displays a call tree.

The report Summary tab indicates that foo2.m contains one call to the eval function which is not supported for code generation. 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 the eval function is not supported for code generation. When you generate a MEX function for foo1, the code generation software automatically calls out to MATLAB for eval. For standalone code generation, it does not generate code for it.

Identify Unsupported Data Types

The coder.screener function identifies data types that are not supported for code generation.

Analyze the MATLAB function foo3 that uses unsupported data types.

function [outSparse,outCategorical] = foo3(inVal,inStr1,inStr2)
    outSparse = sparse(inVal);
    cellArray = {inStr1,inStr2};
    outCategorical = categorical(cellArray);
end
coder.screener('foo3')

The code generation readiness report opens. It provides a summary of the unsupported data types.

The report assigns the code a code readiness score of 2, indicating 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 are not supported for code generation. 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 opens. It provides a summary of the unsupported MATLAB function calls. The function foo5 calls one unsupported MATLAB function.

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

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 some significant changes are required.

  • 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 to 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

expand all

Tips

  • Before using coder.screener, fix issues identified by the code analyzer.

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

Was this topic helpful?