Main Content

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

slreportgen.utils.sortBlocks

SimulinkStateflow 模块进行排序

自 R2022b 起

说明

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

示例

sortedList = slreportgen.utils.sortBlocks(unsortedBlocks,sortMethod) 使用 sortMethodunsortedBlocks 中的元素进行排序。

示例

示例

全部折叠

此示例显示如何使用 slreportgen.utils.sortBlocks 函数按模型布局中的位置从左到右对模型模块进行排序。

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

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

打开并观察模型,看看模块是如何分成行的,以及每行是如何从左到右排序的。

model_name = "sortLeftToRightDemoModel";
open_system(model_name);

使用 slreportgen.finder.BlockFinder 对象在模型中查找模块元素。将模块列表保存在变量 unsortedBlocks 中。

unsortedBlocks = find(BlockFinder(model_name));

使用 slreportgen.utils.sortBlocks 函数按照 leftToRight 排序方法对模块进行排序,并显示排序后的模块名称。验证模块是否排序正确。

sortedBlocks = sortBlocks(unsortedBlocks,"leftToRight");
disp([sortedBlocks.Name]');
    "1.1"
    "1.2"
    "1.3"
    "2.1"
    "2.2"
    "2.3"
    "3.1"
    "3.2"
    "3.3"
    "3.4"
    "3.5"
    "3.6"
    "3.7"

此示例显示如何使用 slreportgen.utils.sortBlocks 函数按模型布局中的位置从上到下对模型模块进行排序。

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

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

打开并观察模型,看看模块是如何分成几列的,以及每列是如何从上到下排序的。

model_name = "sortTopToBottomDemoModel";
open_system(model_name);

使用 slreportgen.finder.BlockFinder 对象在模型中查找模块元素。将模块列表保存在变量 unsortedBlocks 中。

unsortedBlocks = find(BlockFinder(model_name));

使用 slreportgen.utils.sortBlocks 函数按照 topToBottom 排序方法对模块进行排序,并显示排序后的模块名称。验证模块是否排序正确。

sortedBlocks = sortBlocks(unsortedBlocks,"topToBottom");
disp([sortedBlocks.Name]');
    "1.1"
    "1.2"
    "1.3"
    "2.1"
    "2.2"
    "2.3"
    "3.1"
    "3.2"
    "3.3"
    "3.4"
    "3.5"
    "3.6"
    "3.7"

输入参数

全部折叠

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

openExample('rptgenext/SimulinkReportGeneratorFilesExample');

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

示例
模块路径的字符串数组
unsortedBlocks = ["slrgex_f14/Actuator Model",...
                  "slrgex_f14/Aircraft Dynamics Model",...
                  "slrgex_f14/alpha (rad)"];
模块句柄数组
load_system("slrgex_f14");
unsortedList = find_system("slrgex_f14",...
                      findall=true,type="block");
搜索结果对象数组,由 slreportgen.finder 包中的 DiagramFinderBlockFinderChartDiagramFinder 对象返回
import slreportgen.finder.*
load_system("sf_car");
load_system("slrgex_f14");
diagFinder = DiagramFinder("slrgex_f14");
blockFinder = BlockFinder("sf_car");
unsortedBlocks = [find(diagFinder),find(blockFinder)];

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

描述
"alphabetical"

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

"systemAlpha"

按父系统名称的字母顺序对模块进行排序。

"fullPathAlpha"

根据完整模块路径的字母顺序对块进行排序。

"blockType"

根据模块类型的字母顺序对块进行排序。

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

使用从左到右的行对对象按照其在模型布局中的位置进行排序。模型中的一行模块是位于两条水平线之间的模块子组。最小行是不能分成子行的行。

该算法首先将模块分组为最少的行,然后从左到右对每行进行排序。然后,算法将已排序的行从上到下连接起来。

有关示例,请参阅从左到右对 Simulink® 模块进行排序

"topToBottom"

使用从上到下的列按模型布局中的位置对对象进行排序。模型中的一列模块是位于两条垂直线之间的模块子组。最小列是不能分成子列的列。

该算法首先将模块分组为最小列,然后从上到下对每列进行排序。然后,算法将已排序列从左到右连接起来。

有关示例,请参阅从上到下对 Simulink® 模块进行排序

"runtime"

仅对包含 unsortedBlocks 列表中第一个模块的模型中的非虚拟块按执行顺序进行排序。虚拟块和不在第一个模块模型中的块将附加到末尾,不进行排序。多任务系统中的模块根据其执行的任务进行分组。

输出参量

全部折叠

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

版本历史记录

在 R2022b 中推出