Main Content

mlreportgen.finder.MATLABVariableFinder Class

Namespace: mlreportgen.finder
Superclasses: mlreportgen.finder.Finder

MATLAB variable finder object

Since R2022a

Description

Use objects of the mlreportgen.finder.MATLABVariableFinder to find MATLAB® variables by criteria. Then use the find or next methods to get the matching variables as MATLABVariableResult objects.

The mlreportgen.finder.MATLABVariableFinder class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

varFinder = mlreportgen.finder.MATLABVariableFinder creates a MATLABVariableFinder object that finds variables in the base workspace.

varFinder = mlreportgen.finder.MATLABVariableFinder(container) creates a MATLABVariableFinder object that finds variables in the specified workspace, by setting the Container property of the created MATLABVariableFinder object to the value of container.

varFinder = mlreportgen.finder.MATLABVariableFinder(Name1=Value1,Name2=Value2) creates a MATLABVariableFinder object and uses the name-value arguments to set the properties of the created MATLABVariableFinder object.

example

Properties

expand all

Workspace in which to search for variables, specified as one of these values:

ValueWorkspace to Search
"MATLAB"Base workspace
"Global"Global workspace
String scalar or character vector that contains the name or path of a MAT-fileThe specified MAT-file

Attributes

GetAccess
public
SetAccess
public

Data Types: char | string

Whether to enable regular expression name matching, specified as a numeric or logical 1 (true) or 0 (false).

Attributes

GetAccess
public
SetAccess
public

Data Types: logical

Names of variables to search for, specified as a character vector or string scalar that consists of the name of a specific variable or a regular expression. To use a regular expression to match the names of one or more MATLAB variables, set the Regexp property to true.

Attributes

GetAccess
public
SetAccess
public

Data Types: char | string

Whether to include variables related to report generation, such as reporter or finder objects, specified as a logical 1 (true) or 0 (false).

Attributes

GetAccess
public
SetAccess
public

Data Types: logical

Properties of variables to search for, specified as a cell array of name-value arguments. Only variables that have the specified properties are searched for. The valid name-value arguments are:

NameValue
"name"Name of the variable, specified as a string scalar or a character array.
"class"Data type of the variable, specified as a string scalar or a character array.
"size"Dimensions of the variable, specified as a double array.
"bytes"Number of bytes used for storing the variable in the computer memory, specified as a double scalar.
"sparse"Whether the variable is a sparse matrix, specified as a logical.
"complex"Whether the variable is a complex number, specified as a logical.
"global"Whether the variable is global, specified as a logical.

Attributes

GetAccess
public
SetAccess
public

Data Types: cell

Methods

expand all

Examples

collapse all

This example shows how to create an mlreportgen.finder.MATLABVariableFinder object that finds global variables with names that begin with "my", then adds information about the matching variables to an mlreportgen.report.Report object.

Import these MATLAB Report API packages so that you do not have to use long, fully qualified class names.

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

Define the global variables for this example.

global my_global_var1 my_global_var2 other_global_var;
my_global_var1 = "this is the content of my_global_var1";
my_global_var2 = "this is the content of my_global_var2";
other_global_var = "this is the content of other_global_var";

Create an mlreportgen.report.Report object of type PDF. Then create a title and append the title to the Report object.

theReport = Report("MATLABVariableFinder_globals_Example","pdf");
docHeader = Heading(1,"The global variables we found in this example are:");
append(theReport,docHeader);

Create an mlreportgen.finder.MATLABVariableFinder object that finds global variables with names that start with "my".

varFinder = MATLABVariableFinder(Container="Global",Name="^my",Regexp=true);

Use the find method to get an array of mlreportgen.finder.MATLABVariableResult objects that contain information about the matching variables.

finderResults = find(varFinder);

Append the matching variables to the report.

append(theReport,finderResults);

Close the Report object to create the PDF, then open the PDF in an editor.

close(theReport);
rptview(theReport);

Clear the global variables we used.

clear global my_global_var1 my_global_var2 other_global_var;

This example shows how to use the next and hasNext methods to retrieve MATLAB® variables from a MAT-file.

Import these MATLAB Report API packages so that you do not have to use long, fully qualified class names.

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

Create an mlreportgen.report.Report object of type PDF. Then create a title and append it to the Report object.

theReport = Report("MATLABVariableFinder_MAT-file_Example","pdf");
docHeader = Heading(1,"The variables we found in the MAT-file for this example are:");
append(theReport,docHeader);

Create an mlreportgen.finder.MATLABVariableFinder object that finds variables in the MAT-file Example_MAT_file.mat.

varFinder = MATLABVariableFinder("Example_MAT_file.mat");

Use the hasNext and next methods to find the matching variables and append them to the Report object one at a time.

while(hasNext(varFinder))
  append(theReport,next(varFinder));
end

Close the Report object to create the PDF, then open the PDF in an editor.

close(theReport);
rptview(theReport);

Version History

Introduced in R2022a