主要内容

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

slreportgen.utils.sortSystems

Simulink 系统排序

自 R2022b 起

说明

sortedList = slreportgen.utils.sortSystems(systemList) 按名称字母顺序对 systemList 中的元素进行排序。在使用 sortSystems 函数之前,您必须加载包含系统的模型。该函数忽略并排除无效元素。

sortedList = slreportgen.utils.sortSystems(systemList,sortMethod) 使用 sortMethodsystemList 中的元素进行排序。

示例

示例

全部折叠

此示例显示如何使用 slreportgen.utils.sortSystems 函数按模块数对 Simulink 系统进行排序。

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

import slreportgen.finder.*
import slreportgen.utils.*

打开模型并注意每个子系统包含多少个模块。

model_name = "sortSystemsExampleModel";
open_system(model_name);

使用 slreportgen.finder.DiagramFinder 对象来查找并创建模型中的系统列表。显示系统的路径并注意模型本身被视为一个系统。

sysList = find(DiagramFinder(model_name));
disp([sysList.Path]');
    "sortSystemsExampleModel"
    "sortSystemsExampleModel/System1"
    "sortSystemsExampleModel/System2"
    "sortSystemsExampleModel/System3"
    "sortSystemsExampleModel/System4"

使用 slreportgen.utils.sortSystems 函数按模块数对系统进行排序。显示排序列表的路径,并注意 numBlocks 排序选项将子系统视为模块。

sortedList = sortSystems(sysList,"numBlocks");
disp([sortedList.Path]');
    "sortSystemsExampleModel/System4"
    "sortSystemsExampleModel/System1"
    "sortSystemsExampleModel/System3"
    "sortSystemsExampleModel"
    "sortSystemsExampleModel/System2"

输入参数

全部折叠

要排序的 Simulink® 系统列表,指定为以下值之一:

示例: slreportgen.utils.sortSystems(["f14","sf_car","sldemo_fuelsys"])

示例: slreportgen.utils.sortSystems(find_system("f14",findall=true,type="block",blocktype="SubSystem"))

示例: slreportgen.utils.sortSystems([find(slreportgen.finder.DiagramFinder("sf_car")),find(slreportgen.finder.DiagramFinder("sldemo_fuelsys"))])

排序方法,指定为以下值之一:

  • "alphabetical" - 按名称将对象按字母顺序排序。

  • "numBlocks" - 按系统中的模块数量从大到小对系统进行排序。有关示例,请参阅按模块数对 Simulink® 系统进行排序

  • "depth" - 按模型层次结构中的深度对系统进行排序,其中子系统位于其包含的子系统之前。

输出参量

全部折叠

排序列表,以字符串数组、句柄数组或 slreportgen.finder.DiagramResult 对象数组形式返回。返回的数组与 systemList 类型相同。

版本历史记录

在 R2022b 中推出