Main Content

mlreportgen.report.MATLABCode Class

Namespace: mlreportgen.report

MATLAB code reporter

Since R2021a

Description

Use an object of the mlreportgen.report.MATLABCode class to include syntax-highlighted MATLAB® code in a report.

The mlreportgen.report.MATLABCode class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

reporter = mlreportgen.report.MATLABCode() creates an empty MATLABCode reporter object based on the default template. You must specify the MATLAB code file by setting the FileName property, or specify the code content by setting the Content property. Use other properties to specify reporter options.

example

reporter = mlreportgen.report.MATLABCode(filename) creates a MATLABCode reporter with the FileName property set to filename.

reporter = mlreportgen.report.MATLABCode(Name=Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Properties

expand all

Path and file name of the file that contains MATLAB code, specified as a character vector or string scalar. The file can have a .m or .mlx extension. If you set this property, the MATLABCode reporter sets the Content property to a string scalar that contains the code contained in the specified file.

Attributes:

GetAccess
public
SetAccess
public
Dependent
true
NonCopyable
true

MATLAB code, specified as a character vector or string scalar. Set this property only if the FileName property is not set.

Attributes:

GetAccess
public
SetAccess
public
Dependent
true
NonCopyable
true

Whether to apply smart indenting to the code, specified as true or false.

Attributes:

GetAccess
public
SetAccess
public

Whether to include code complexity, specified as true or false. If the value is true, the report includes the McCabe cyclomatic complexity of each function that the MATLAB code contains.

Attributes:

GetAccess
public
SetAccess
public

Code complexity reporter, specified as an mlreportgen.report.BaseTable object. The BaseTable reporter is used to report and format the code complexity tabular data. The default value of this property is a BaseTable object with the TableStyleName property set to "MATLABCodeTable" and the other properties set to default values. You can customize the appearance of the table by customizing the default reporter or by replacing it with a custom BaseTable reporter. Any content that you specify in the Title property of the default or the replacement BaseTable reporter appears before the title in the generated report.

Attributes:

GetAccess
public
SetAccess
public

Source of the template for this reporter, specified as one of these options:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template is used for this reporter or whose template library contains the template for this reporter

  • DOM document or document part whose template is used for this reporter or whose template library contains the template for this reporter

The specified template must be the same type as the report to which this reporter is appended. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Name of the template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template source (TemplateSrc) for this reporter.

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID or as an mlreportgen.dom.LinkTarget object. A character vector or string scalar value is converted to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Methods

expand all

Examples

collapse all

Report the syntax-highlighted code for the function myAdd.m.

Create a report.

import mlreportgen.dom.*
import mlreportgen.report.*

rpt = Report("MyReport","pdf");

Create a chapter.

chap = Chapter("The myAdd Function");

Create a MATLABCode reporter to report on the content of myAdd.m.

mCode = MATLABCode("myAdd.m");

Add the reporter to the chapter and the chapter to the report.

append(chap,mCode);
append(rpt,chap);

Close the report and open the viewer.

close(rpt);
rptview(rpt);

Here is the syntax-highlighted code in the report.

Version History

Introduced in R2021a