mlreportgen.finder.MATLABVariableFinder Class
Namespace: mlreportgen.finder
Superclasses: mlreportgen.finder.Finder
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.
Creation
Description
creates a varFinder
= mlreportgen.finder.MATLABVariableFinderMATLABVariableFinder
object that finds variables in the base
workspace.
creates a varFinder
= mlreportgen.finder.MATLABVariableFinder(container
)MATLABVariableFinder
object that finds variables in the specified
workspace, by setting the Container property of the
created MATLABVariableFinder
object to the value of
container
.
creates a varFinder
= mlreportgen.finder.MATLABVariableFinder(Name1=Value1
,Name2=Value2
)MATLABVariableFinder
object and uses the name-value arguments to
set the properties of the created MATLABVariableFinder
object.
Properties
Container
— Workspace in which to search for variables
"MATLAB"
(default) | "Global"
| string scalar | character vector
Workspace in which to search for variables, specified as one of these values:
Value | Workspace to Search |
---|---|
"MATLAB" | Base workspace |
"Global" | Global workspace |
String scalar or character vector that contains the name or path of a MAT-file | The specified MAT-file |
Attributes
GetAccess | public |
SetAccess | public |
Data Types: char
| string
Regexp
— Enable regular expression name matching
false
or 0
(default) | true
or 1
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
Name
— Names of variables to search for
character vector | string scalar
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
IncludeReportVariables
— Whether to include variables related to report generation
false
or 0
(default) | true
or 1
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
— Properties of variables to search for
cell array
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:
Name | Value |
---|---|
"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
Public Methods
Note
This finder provides these options to get search results:
To return the search results as an array, use the
find
method. Add the results directly to a report or process the results in afor
-loop.To iterate through the results one at a time, use the
hasNext
andnext
methods in awhile
-loop.
Neither option has a performance advantage.
find |
|
hasNext |
|
next |
|
Examples
Find and Report on Specific Global Variables
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;
Find and Report Individual Variables Iteratively
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)