Main Content

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

slreportgen.utils.sortSystems

SimulinkStateflow 系统进行排序

自 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"

输入参数

全部折叠

运行以下命令访问本示例中使用的支持文件。

openExample('rptgenext/SimulinkReportGeneratorFilesExample');

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

示例
模型名称的字符串数组
systemList = ["slrgex_f14",...
              "sf_car",...
              "slrgex_fuelsys",...
              "slrgex_radar_eml"];
系统句柄数组
load_system("slrgex_f14");

systemList = find_system("slrgex_f14",findall=true,...
                  type="block",blocktype="SubSystem");
slreportgen.finder.DiagramFinder 对象返回的 slreportgen.finder.DiagramResult 数组
import slreportgen.finder.*

load_system("slrgex_f14");
load_system("sf_car");

finder1 = DiagramFinder("sf_car");
finder2 = DiagramFinder("slrgex_fuelsys");

systemList = [find(finder1) find(finder2)];

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

描述
"alphabetical"

按名称的字母顺序对对象进行排序。

"numBlocks"

按系统中的模块数从大到小对系统进行排序。

"depth"

按模型层次结构的深度对对象进行排序,其中一个子系统位于包含它的子系统之前。

输出参量

全部折叠

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

版本历史记录

在 R2022b 中推出