mlreportgen.finder.MATLABVariableFinder 类
命名空间: mlreportgen.finder
超类: mlreportgen.finder.Finder
描述
使用 mlreportgen.finder.MATLABVariableFinder
的对象按标准查找 MATLAB® 变量。然后使用 find
或 next
方法将匹配的变量作为 MATLABVariableResult
对象获取。
mlreportgen.finder.MATLABVariableFinder
类是一个 handle
类。
创建对象
描述
创建一个 varFinder
= mlreportgen.finder.MATLABVariableFinderMATLABVariableFinder
对象,该对象在基础工作区中查找变量。
通过将创建的 varFinder
= mlreportgen.finder.MATLABVariableFinder(container
)MATLABVariableFinder
对象的 Container属性设置为 container
的值,创建一个在指定工作区中查找变量的 MATLABVariableFinder
对象。
创建一个 varFinder
= mlreportgen.finder.MATLABVariableFinder(Name1=Value1
,Name2=Value2
)MATLABVariableFinder
对象并使用名称值参量来设置创建的 MATLABVariableFinder
对象的属性。
属性
Container
— 搜索变量的工作区
"MATLAB"
(默认) | "Global"
| 字符串标量 | 字符向量
用于搜索变量的工作区,指定为以下值之一:
值 | 要搜索的工作区 |
---|---|
"MATLAB" | 基础工作区 |
"Global" | 全局工作区 |
包含 MAT 文件的名称或路径的字符串标量或字符向量 | 指定的 MAT 文件 |
属性
GetAccess | public |
SetAccess | public |
数据类型: char
| string
Regexp
— 启用正则表达式名称匹配
false
或 0
(默认) | true
或 1
是否启用正则表达式名称匹配,指定为数字或逻辑 1
(true
)或 0
(false
)。
属性
GetAccess | public |
SetAccess | public |
数据类型: logical
Name
— 要搜索的变量名称
字符向量 | 字符串标量
要搜索的变量的名称,指定为由特定变量或正则表达式的名称组成的字符向量或字符串标量。要使用正则表达式匹配一个或多个 MATLAB 变量的名称,请将 Regexp
属性设置为 true
。
属性
GetAccess | public |
SetAccess | public |
数据类型: char
| string
IncludeReportVariables
— 是否包含与报告生成相关的变量
false
或 0
(默认) | true
或 1
是否包含与报告生成相关的变量,例如报告器或查找器对象,指定为逻辑 1
(true
) 或 0
(false
)。
属性
GetAccess | public |
SetAccess | public |
数据类型: logical
Properties
— 要搜索的变量的属性
元胞数组
要搜索的变量的属性,指定为名称-值参量的元胞数组。仅搜索具有指定属性的变量。有效的名称-值参量是:
名称 | 值 |
---|---|
"name" | 变量的名称,指定为字符串标量或字符数组。 |
"class" | 变量的数据类型,指定为字符串标量或字符数组。 |
"size" | 变量的维度,指定为双数组。 |
"bytes" | 用于在计算机内存中存储变量的字节数,指定为双精度标量。 |
"sparse" | 变量是否是稀疏矩阵,指定为逻辑。 |
"complex" | 变量是否为复数,指定为逻辑。 |
"global" | 变量是否是全局的,指定为逻辑。 |
属性
GetAccess | public |
SetAccess | public |
数据类型: cell
方法
公共方法
注意
此查找器提供了以下选项来获取搜索结果:
要将搜索结果作为数组返回,请使用
find
方法。将结果直接添加到报告中或在for
循环中处理结果。要一次迭代结果,请在
while
循环中使用hasNext
和next
方法。
这两种选择都没有性能优势。
find |
|
hasNext | 如果变量可供 |
next |
|
示例
查找并报告特定全局变量
此示例显示如何创建一个 mlreportgen.finder.MATLABVariableFinder
对象,该对象查找名称以 "my" 开头的全局变量,然后将有关匹配变量的信息添加到 mlreportgen.report.Report
对象。
导入这些 MATLAB 报 告 API 包,这样您就不必使用长而完全限定的类名。
import mlreportgen.report.* import mlreportgen.finder.* import mlreportgen.dom.*
为此示例定义全局变量。
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";
创建 PDF 类型的 mlreportgen.report.Report
对象。然后创建一个标题并将标题追加到 Report
对象。
theReport = Report("MATLABVariableFinder_globals_Example","pdf"); docHeader = Heading(1,"The global variables we found in this example are:"); append(theReport,docHeader);
创建一个 mlreportgen.finder.MATLABVariableFinder
对象,查找名称以 "my" 开头的全局变量。
varFinder = MATLABVariableFinder(Container="Global",Name="^my",Regexp=true);
使用 find
方法获取包含有关匹配变量的信息的 mlreportgen.finder.MATLABVariableResult
对象数组。
finderResults = find(varFinder);
将匹配的变量追加到报告中。
append(theReport,finderResults);
关闭 Report
对象以创建 PDF,然后在编辑器中打开 PDF。
close(theReport); rptview(theReport);
清除我们使用的全局变量。
clear global my_global_var1 my_global_var2 other_global_var;
迭代查找并报告单个变量
此示例显示如何使用 next
和 hasNext
方法从 MAT 文件中检索 MATLAB® 变量。
导入这些 MATLAB 报 告 API 包,这样您就不必使用长而完全限定的类名。
import mlreportgen.report.* import mlreportgen.finder.* import mlreportgen.dom.*
创建 PDF 类型的 mlreportgen.report.Report
对象。然后创建一个标题并将其追加到 Report
对象。
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);
创建一个 mlreportgen.finder.MATLABVariableFinder
对象,用于在 MAT 文件 Example_MAT_file.mat
中查找变量。
varFinder = MATLABVariableFinder("Example_MAT_file.mat");
使用 hasNext
和 next
方法查找匹配的变量并将它们逐个追加到 Report
对象。
while(hasNext(varFinder)) append(theReport,next(varFinder)); end
关闭 Report
对象以创建 PDF,然后在编辑器中打开 PDF。
close(theReport); rptview(theReport);
版本历史记录
在 R2022a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)