Main Content

本页采用了机器翻译。点击此处可查看最新英文版本。

mlreportgen.finder.MATLABVariableFinder 类

命名空间: mlreportgen.finder
超类: mlreportgen.finder.Finder

MATLAB 变量查找器对象

自 R2022a 起

描述

使用 mlreportgen.finder.MATLABVariableFinder 的对象按标准查找 MATLAB® 变量。然后使用 findnext 方法将匹配的变量作为 MATLABVariableResult 对象获取。

mlreportgen.finder.MATLABVariableFinder 类是一个 handle 类。

类属性

HandleCompatible
true

有关类属性的信息,请参阅类属性

创建对象

描述

varFinder = mlreportgen.finder.MATLABVariableFinder 创建一个 MATLABVariableFinder 对象,该对象在基础工作区中查找变量。

varFinder = mlreportgen.finder.MATLABVariableFinder(container) 通过将创建的 MATLABVariableFinder 对象的 Container属性设置为 container 的值,创建一个在指定工作区中查找变量的 MATLABVariableFinder 对象。

varFinder = mlreportgen.finder.MATLABVariableFinder(Name1=Value1,Name2=Value2) 创建一个 MATLABVariableFinder 对象并使用名称值参量来设置创建的 MATLABVariableFinder 对象的属性。

示例

属性

全部展开

用于搜索变量的工作区,指定为以下值之一:

要搜索的工作区
"MATLAB"基础工作区
"Global"全局工作区
包含 MAT 文件的名称或路径的字符串标量或字符向量指定的 MAT 文件

属性

GetAccess
public
SetAccess
public

数据类型: char | string

是否启用正则表达式名称匹配,指定为数字或逻辑 1true)或 0false)。

属性

GetAccess
public
SetAccess
public

数据类型: logical

要搜索的变量的名称,指定为由特定变量或正则表达式的名称组成的字符向量或字符串标量。要使用正则表达式匹配一个或多个 MATLAB 变量的名称,请将 Regexp 属性设置为 true

属性

GetAccess
public
SetAccess
public

数据类型: char | string

是否包含与报告生成相关的变量,例如报告器或查找器对象,指定为逻辑 1 (true) 或 0 (false)。

属性

GetAccess
public
SetAccess
public

数据类型: logical

要搜索的变量的属性,指定为名称-值参量的元胞数组。仅搜索具有指定属性的变量。有效的名称-值参量是:

名称
"name"变量的名称,指定为字符串标量或字符数组。
"class"变量的数据类型,指定为字符串标量或字符数组。
"size"变量的维度,指定为双数组。
"bytes"用于在计算机内存中存储变量的字节数,指定为双精度标量。
"sparse"变量是否是稀疏矩阵,指定为逻辑。
"complex"变量是否为复数,指定为逻辑。
"global"变量是否是全局的,指定为逻辑。

属性

GetAccess
public
SetAccess
public

数据类型: cell

方法

全部展开

示例

全部折叠

此示例显示如何创建一个 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;

此示例显示如何使用 nexthasNext 方法从 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");

使用 hasNextnext 方法查找匹配的变量并将它们逐个追加到 Report 对象。

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

关闭 Report 对象以创建 PDF,然后在编辑器中打开 PDF。

close(theReport);
rptview(theReport);

版本历史记录

在 R2022a 中推出