Main Content

mlreportgen.finder.MATLABVariableResult Class

Namespace: mlreportgen.finder
Superclasses: mlreportgen.finder.Result

MATLAB variable search result object

Since R2022a

Description

An object of the mlreportgen.finder.MATLABVariableResult class is the result of a search for MATLAB® variables. A MATLABVariableResult object contains information about a single variable. Each MATLABVariableResult object is associated with an mlreportgen.report.MATLABVariable reporter object that represents the same MATLAB variable. To report on the variable, add the MATLABVariableResult object to a generated report.

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

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

You do not create MATLABVariableResult objects explicitly. The MATLABVariableFinder methods find and next create a MATLABVariableResult object for each variable they find.

Properties

expand all

Name of the variable represented by this MATLABVariableResult object, returned as a string scalar.

Attributes

GetAccess
public
SetAccess
protected

Data Types: string

Workspace in which the variable is defined, specified as one of these values:

ValueWorkspace
"MATLAB"Base workspace
"Global"Global workspace
"MAT-File" A MAT-file

Attributes

GetAccess
public
SetAccess
Restricts access

Data Types: string

Name of the MAT-file in which the variable is defined, specified as a string scalar. If the variable is not defined in a MAT-file, FileName is empty.

Attributes

GetAccess
public
SetAccess
Restricts access

Data Types: string

Optional label, specified as any type of MATLAB variable.

Attributes

GetAccess
public
SetAccess
public

Methods

expand all

Examples

collapse all

This example shows how to add summary tables with information about MATLAB® variables to a report.

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

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

Define variables and global variables of different data types and sizes in the base workspace.

global gvar_string gvar_str_arr_2x3 gvar_uint8_arr_9x3;
gvar_string = "this is my string scalar variable";
gvar_str_arr_2x3 = ["str 1.1","str 1.2","str 1.3";"str 2.1","str 2.2","str 2.3"];
gvar_uint8_arr_9x3 = uint8(randi(255,9,3));

var_char_arr = 'this is my character vector variable';
var_double_3x5x6 = rand(3,5,6);
var_cell_arr_7x8x9 = num2cell(rand(7,8,9));

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

rpt = Report("Summary_of_variables_example","pdf");
docHeader = Heading(1,"Summary of variables we found:");
append(rpt,docHeader);

Use the mlreportgen.finder.MATLABVariableFinder.find method to find the variables in the base workspace, and create an array of mlreportgen.finder.MATLABVariableResult objects that represent the variables.

results = find(MATLABVariableFinder());

Create an mlreportgen.report.SummaryTable object with the result array. The default title of the table is the return value of the getDefaultSummaryTableTitle method, and the default list of properties to be reported in the table is the return value of the getDefaultSummaryProperties method. Leave the title of the table and list of properties to be reported in the table unchanged.

table1 = SummaryTable(results);

Create a second SummaryTable object with the result array. Then set the title of this table to "global or not", and set the properties to be reported by this table to "Name" and "Global".

table2 = SummaryTable(results);
table2.Title = "global or not";
table2.Properties = ["Name","Global"];

Append the two summary tables to the report. Then close and view the report.

append(rpt,table1);
append(rpt,table2);
close(rpt);
rptview(rpt);

This example shows how to create a hyperlink to a variable in a report.

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

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

Define variables in the base workspace.

for index = 1:99
  evalin("base",sprintf("var_%0.3i='this is the content of var_%0.2i';",index,index));
end

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

rpt = Report("MATLABVariableResult_hyperlink_Example","html-file");
header = Heading(1,"These are the variables we found:");
append(rpt,header);

Use the mlreportgen.finder.MATLABVariableFinder.find method to find variables in the base workspace that have names beginning with "var", and create a vector of mlreportgen.finder.MATLABVariableResult objects that represent the variables. Then append the result objects to the report.

results = find(MATLABVariableFinder(Name="^var"));
append(rpt,results);

Create an mlreportgen.dom.InternalLink object with the link target ID of result number 31. Then append the InternalLink object to the report.

targetID = getReporterLinkTargetID(results(31));
link = InternalLink(targetID,"Jump to result #31");
append(rpt,link);

Close and view the report.

close(rpt);
rptview(rpt);

Scroll to the bottom of the report to test the hyperlink.

Version History

Introduced in R2022a