Main Content

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

slreportgen.utils.sortObjects

SimulinkStateflow 对象进行排序

自 R2022b 起

说明

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

sortedList = slreportgen.utils.sortObjects(objectList,sortMethod) 使用 sortMethodobjectList 中的元素进行排序。

示例

示例

全部折叠

此示例显示如何使用 slreportgen.utils.sortObjects 函数按深度对 Simulink 对象进行排序。

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

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

加载 Simulink 模型 sortByDepthExampleModel

model_name = "sortByDepthExampleModel";
load_system(model_name)

使用 slreportgen.finder.DiagramFinder 对象查找模型中的所有系统,包括模型本身。然后创建一个空的 slreportgen.finder.BlockResult 数组。

sysArray = find(DiagramFinder(model_name));
unsortedList = BlockResult.empty;

遍历 sysArray 并使用 slreportgen.finder.BlockFinder 对象搜索每个子系统中的模块。对于每个子系统,将搜索结果模块数组附加到 unsortedList 数组的末尾。

for idx = 1:length(sysArray)
  curBlockFinder = BlockFinder(sysArray(idx));
  curBlockFinder.BlockTypes = ["Inport","Gain","Outport"];
  curSysBlocks = find(curBlockFinder);
  unsortedList(end+1:end+length(curSysBlocks)) = curSysBlocks;
end

显示 unsortedList 中模块的路径以查看它们是如何排序的。

disp([unsortedList.BlockPath]');
    "sortByDepthExampleModel/In0"
    "sortByDepthExampleModel/Gain0"
    "sortByDepthExampleModel/Out0"
    "sortByDepthExampleModel/Sub1/In1"
    "sortByDepthExampleModel/Sub1/Gain1"
    "sortByDepthExampleModel/Sub1/Out1"
    "sortByDepthExampleModel/Sub1/Sub3/In3"
    "sortByDepthExampleModel/Sub1/Sub3/Gain3"
    "sortByDepthExampleModel/Sub1/Sub3/Out3"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/In4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Gain4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Out4"
    "sortByDepthExampleModel/Sub1/Sub5/In5"
    "sortByDepthExampleModel/Sub1/Sub5/Gain5"
    "sortByDepthExampleModel/Sub1/Sub5/Out5"
    "sortByDepthExampleModel/Sub2/In2"
    "sortByDepthExampleModel/Sub2/Gain2"
    "sortByDepthExampleModel/Sub2/Out2"

使用 slreportgen.utils.sortObjects 函数按深度对 unsortedList 中的模块进行排序。然后显示已排序模块的路径以验证它们是否按深度排序。

sortedList = sortObjects(unsortedList,"depth");
disp([sortedList.BlockPath]');
    "sortByDepthExampleModel/In0"
    "sortByDepthExampleModel/Gain0"
    "sortByDepthExampleModel/Out0"
    "sortByDepthExampleModel/Sub1/In1"
    "sortByDepthExampleModel/Sub1/Gain1"
    "sortByDepthExampleModel/Sub1/Out1"
    "sortByDepthExampleModel/Sub2/In2"
    "sortByDepthExampleModel/Sub2/Gain2"
    "sortByDepthExampleModel/Sub2/Out2"
    "sortByDepthExampleModel/Sub1/Sub3/In3"
    "sortByDepthExampleModel/Sub1/Sub3/Gain3"
    "sortByDepthExampleModel/Sub1/Sub3/Out3"
    "sortByDepthExampleModel/Sub1/Sub5/In5"
    "sortByDepthExampleModel/Sub1/Sub5/Gain5"
    "sortByDepthExampleModel/Sub1/Sub5/Out5"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/In4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Gain4"
    "sortByDepthExampleModel/Sub1/Sub3/Sub4/Out4"

输入参数

全部折叠

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

openExample('rptgenext/SimulinkReportGeneratorFilesExample');

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

示例
模型名称和模块路径的字符串数组
objectList = ["slrgex_f14",...
              "slrgex_f14/Actuator Model",...
              "slrgex_f14/Aircraft Dynamics Model",...
              "sf_car",...
              "slrgex_fuelsys",...
              "slrgex_radar_eml"];
模型和模块句柄数组
load_system("slrgex_f14");
objectList = find_system("slrgex_f14",findall=true);
搜索结果对象数组,由 slreportgen.finder 包中的 DiagramElementFinderBlockFinderSignalFinderAnnotationFinder 对象返回
import slreportgen.finder.*

load_system("sf_car");
load_system("slrgex_fuelsys");

blockFinder = BlockFinder("sf_car");
sigFinder = SignalFinder("slrgex_fuelsys");

objectList = [find(blockFinder) find(sigFinder)];

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

描述
"alphabetical"

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

"systemAlpha"

按父系统名称的字母顺序对对象进行排序

"depth"

按模型层次结构的深度对对象进行排序,其中一个子系统位于包含它的子系统之前。有关示例,请参阅按深度对 Simulink® 对象进行排序

输出参量

全部折叠

排序列表,以字符串数组、句柄数组或搜索结果对象数组的形式返回。返回的数组与 objectList 类型相同。

版本历史记录

在 R2022b 中推出