主要内容

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

slreportgen.finder.FunctionReferenceFinder 类

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

MATLAB 模块中查找 Simulink 函数引用

自 R2022a 起

描述

使用 slreportgen.finder.FunctionReferenceFinder 类的对象来查找专门用于计算 Simulink® 模块中的参数的函数引用。

slreportgen.finder.FunctionReferenceFinder 类是 handle 类。

类属性

HandleCompatible
true

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

创建对象

描述

funcRefFinder = slreportgen.finder.FunctionReferenceFinder(container) 创建一个 FunctionReferenceFinder 对象并将 Container 属性设置为 container

theReporter = slreportgen.finder.FunctionReferenceFinder(Name=Value) 使用一个或多个名称-值参量设置 属性

示例

属性

全部展开

Simulink 模型或模块来搜索函数引用,指定为以下值之一:

描述
模型名称模型名称,指定为字符向量或字符串标量。例如,"sf_car"
模块路径模块路径,指定为字符向量或字符串标量。例如 "sf_car/Engine"
模型句柄模型句柄,由 slreportgen.utils.getModelHandle 函数生成。例如 slreportgen.utils.getModelHandle("sf_car")
模块句柄模块句柄,由 getSimulinkBlockHandle 函数生成。例如,getSimulinkBlockHandle("sf_car/Engine")
slreportgen.finder.DiagramResult 对象代表 Simulink 模型或子系统的搜索结果对象
slreportgen.finder.BlockResult 对象代表 Simulink 模块的搜索结果对象

属性:

GetAccess
公共
SetAccess
公共

容器内部搜索的级别数,指定为非负整数或 Inf 以在无限深度中进行搜索。

属性:

GetAccess
公共
SetAccess
公共

数据类型: double

要搜索的函数类型,指定为以下值之一:

描述
"all"搜索所有函数引用
"built-in"搜索内置函数引用
"user-defined"搜索用户定义函数引用

属性:

GetAccess
公共
SetAccess
公共

数据类型: string | char

是否在引用模型中搜索,指定为数值或逻辑值 1 (true) 或 0 (false)。您可以在模型引用的模型或由 Container 属性表示的模块引用的模型中进行搜索。当 SearchReferencedModels 为 true 时:

  • 查找器仅搜索搜索深度内的引用模型。

  • 查找器将搜索引用模型到 SearchDepth 指定的深度,而不管包含引用模型的模块的深度是多少。

  • 查找器搜索被引用模型所引用的模型。

注意

您还可以使用 SearchReferencedModels"off" 设置 "on" 属性。

属性:

GetAccess
公共
SetAccess
公共

数据类型: logical

是否在封装子系统中进行搜索,指定为以下值之一。

描述
true在封装子系统中搜索变量。(默认)
false不在封装子系统中搜索变量。

数据类型: logical

是否跟随库链接,指定为以下值之一:

描述
true按照链接进入库模块图。库链接被视为子系统。(默认)
false不要点击链接进入库模块。库链接被视为模块。

属性:

GetAccess
公共
SetAccess
公共

数据类型: logical

是否搜索变体子系统和模型变体中非活动变体引用的函数,指定为逻辑值 1 (true) 或 0 (false)

属性:

GetAccess
公共
SetAccess
公共

数据类型: logical

要查找的函数的属性,指定为名称-值参量的元胞数组,格式为 {"Name","Value"}。查找器仅返回具有指定属性和指定值的函数。支持的属性包括 slreportgen.finder.FunctionReferenceResult 类的任何属性。

属性:

GetAccess
公共
SetAccess
公共

数据类型: cell

方法

全部展开

示例

全部折叠

此示例显示如何在 Simulink 模块中查找和报告 MATLAB 函数引用。

导入这些命名空间,这样您就不必使用长而完全限定的类名。

import slreportgen.report.*
import slreportgen.finder.*

创建 PDF 类型的 slreportgen.report.Report

theReport = Report("FunctionReferenceReport","pdf");

打开模型 sldemo_fuelsys,然后编译模型,以便查找器搜索最新版本的模型。

modelName = "sldemo_fuelsys";
open_system(modelName);
slreportgen.utils.compileModel(modelName);

创建一个 slreportgen.finder.FunctionReferenceFinder 对象。

funcRefFinder = FunctionReferenceFinder(modelName);

设置查找器在引用模型中搜索。

funcRefFinder.SearchReferencedModels = true;

使用方法 hasNextnext 逐一获取 slreportgen.finder.FunctionReferenceResult 对象。

while(hasNext(funcRefFinder))
  nextRes = next(funcRefFinder);

如果引用的函数是内置函数,则将结果直接附加到报告中。

  if(nextRes.FunctionType == "built-in")
    append(theReport,nextRes);

如果引用的是用户定义函数,则获取该结果的 slreportgen.report.FunctionReference 报告器的句柄。通过将报告器的 ShowReferencesTable 属性设置为 false 来自定义报告器以排除引用表。然后将报告器附加到报告中。

  else
    reporter = getReporter(nextRes);
    reporter.ShowReferencesTable = false;
    append(theReport,reporter);
  end
end

取消编译并关闭模型。

slreportgen.utils.uncompileModel(modelName)
close_system(modelName);

关闭并查看报告。

close(theReport);
rptview(theReport);

版本历史记录

在 R2022a 中推出