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 as code generation compliance issues. It displays the code generation compliance issues in a report. Iffcncalls other functions directly or indirectly that are not MathWorks®functions,coder.screeneranalyzes these functions. It does not analyze MathWorks functions. It is possible thatcoder.screenerdoes not detect all code generation issues. Under certain circumstances, it is possible thatcoder.screenerreports 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. Specify as a character vector or a string scalar.

fcn_1,...,fcn_n

Comma-separated list of names of entry-point MATLAB functions that you want to analyze. Specify as character vectors or string scalars.

Examples

collapse all

Thecoder.screenerfunction identifies calls to functions that are not supported for code generation. It checks both the entry-point function,foo1, and the functionfoo2thatfoo1calls.

Write the functionfoo2and save it in the filefoo2.m.

functionout = foo2(in) out = eval(in);end

Write the functionfoo1that callsfoo2. Savefoo1in the filefoo1.m.

function= = foo1(在)foo2(in); disp(out);end

Analyzefoo1.

coder.screener('foo1')

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

In the report, click theCode Structuretab and select theShow MATLAB functionscheck 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:

  • Colorsfoo1.mgreen to indicate that it is suitable for code generation.

  • Colorsfoo2.myellow to indicate that it requires significant changes.

  • Assignsfoo1.ma code generation readiness score of 4 andfoo2.ma 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 reportSummarytab indicates thatfoo2.mcontains one call to theevalfunction, which code generation does not support. To generate a MEX function forfoo2.m, modify the code to make the call toevalextrinsic.

functionout = 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 theevalfunction. When you generate a MEX function forfoo1, the code generator dispatchesevalto MATLAB for execution. For standalone code generation, the code generator does not generate code foreval.

Thecoder.screenerfunction identifies MATLAB data types that code generation does not support.

Write the functionmyfunthat contains a MATLAB table.

functionoutTable = myfun1(A) outTable = table(A);end

Analyzemyfun.

coder.screener(“myfun1”);

The code generation readiness report indicates that table data types are not supported for code generation.

The report assignsmyfun1a code readiness score of3. Before generating code, you must fix the reported issues.

Tips

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

  • Before generating code, usecoder.screenerto check that a function is suitable for code generation. Fix all the issues that it detects.

  • It is possible thatcoder.screenerdoes not detect all issues, and can report false errors. Therefore, before generating C code, verify that your code is suitable for code generation by generating a MEX function.

介绍了R2012b

Was this topic helpful?