Main Content

coder.screener

Determine if function is suitable for code generation

Description

example

coder.screener(fcn) analyzes the entry-point MATLAB® function fcn to identify unsupported functions and language features as code generation compliance issues. The code generation compliance issues are displayed in the readiness report.

If fcn calls other functions directly or indirectly that are not MathWorks® functions (MATLAB built-in functions and toolbox functions), coder.screener analyzes these functions. It does not analyze the MathWorks functions.

It is possible that coder.screener does not detect all code generation issues. Under certain circumstances, it is possible that coder.screener reports false errors.

To avoid undetected code generation issues and false errors, before generating code, verify that your MATLAB code is suitable for code generation by performing these additional checks:

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

  • After using coder.screener, and before generating C/C++ code, verify that your MATLAB code is suitable for code generation by generating and verifying a MEX function.

The coder.screener function does not report functions that the code generator treats as extrinsic. Examples of such functions are plot, disp, and figure. See Extrinsic Functions.

example

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

Examples

collapse all

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

Write the function foo2 and save it in the file foo2.m.

function tf = foo2(source,target)
G = digraph(source,target);
tf = isdag(G);
end

Write the function foo1 that calls foo2. Save foo1 in the file foo1.m.

function tf = foo1(source,target)
assert(numel(source)==numel(target))
tf = foo2(source,target);
end

Analyze foo1.

coder.screener('foo1')

The Code Generation Readiness report displays a summary of the unsupported MATLAB function calls. The report Summary tab indicates that foo2.m contains one call to the digraph function and one call to the isdag function, which are not supported for code generation.

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. The report displays:

  • Green: Function (foo1.m) suitable for code generation.

  • Yellow: Function (foo2.m) requires significant changes.

The report also displays a Call Tree with Code Generation Readiness Score. 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. In this example, the report assigns foo1.m a code generation readiness score of 4 and foo2.m a score of 3.

The function foo2 calls two unsupported MATLAB functions. To generate a MEX function, modify the code to make the calls to digraph and isdag extrinsic by using the coder.extrinsic directive, and then rerun the code generation readiness tool.

function tf = foo2(source,target)
coder.extrinsic('digraph','isdag');
G = digraph(source,target);
tf = isdag(G);
end

Rerun coder.screener on the entry-point function foo1.

coder.screener('foo1')

The report no longer flags that code generation does not support the digraph and dag functions. When you generate a MEX function for foo1, the code generator dispatches these two functions to MATLAB for execution.

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

Write the function myfun1 that contains a MATLAB calendar duration array data type.

function out = myfun1(A)
out = calyears(A);
end

Analyze myfun1.

coder.screener('myfun1');

The code generation readiness report indicates that the calyears data type is not supported for code generation.

The report assigns myfun1 a code generation readiness score of 3. Before generating code, fix the reported issues.

Input Arguments

collapse all

Name of entry-point MATLAB function for analysis. Specify as a character vector or a string scalar.

Example: coder.screener('myfun');

Data Types: char | string

Comma-separated list of entry-point MATLAB function names for analysis. Specify as character vectors or string scalars.

Example: coder.screener('myfun1','myfun2');

Data Types: char | string

Limitations

  • The coder.screener function is not supported in MATLAB Online™.

Introduced in R2012b