slreportgen.utils.sortBlocks
语法
说明
按名称字母顺序对 sortedList
= slreportgen.utils.sortBlocks(unsortedBlocks
)unsortedBlocks
中的元素进行排序。在使用 sortBlocks
函数之前,您必须加载包含模块的模型。该函数忽略并排除无效元素。
使用 sortedList
= slreportgen.utils.sortBlocks(unsortedBlocks
,sortMethod
)sortMethod
对 unsortedBlocks
中的元素进行排序。
示例
从左到右对 Simulink 模块进行排序
此示例显示如何使用 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"
从上到下对 Simulink 模块进行排序
此示例显示如何使用 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"
输入参数
unsortedBlocks
— 要排序的模块列表
字符串数组 | 句柄数组 | 搜索结果对象数组
运行以下命令访问本示例中使用的支持文件。
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 包中的 DiagramFinder 、BlockFinder 、ChartDiagramFinder 对象返回 | import slreportgen.finder.* load_system("sf_car"); load_system("slrgex_f14"); diagFinder = DiagramFinder("slrgex_f14"); blockFinder = BlockFinder("sf_car"); unsortedBlocks = [find(diagFinder),find(blockFinder)]; |
sortMethod
— 排序方法
"alphabetical"
| "systemAlpha"
| "fullPathAlpha"
| "blockType"
| "depth"
| "leftToRight"
| "topToBottom"
| "runtime"
排序方法,指定为以下值之一:
值 | 描述 |
---|---|
"alphabetical" | 按名称的字母顺序对模块进行排序。 |
"systemAlpha" | 按父系统名称的字母顺序对模块进行排序。 |
"fullPathAlpha" | 根据完整模块路径的字母顺序对块进行排序。 |
"blockType" | 根据模块类型的字母顺序对块进行排序。 |
"depth" | 按模型层次结构的深度对模块进行排序,其中一个子系统位于包含它的子系统之前。 |
"leftToRight" | 使用从左到右的行对对象按照其在模型布局中的位置进行排序。模型中的一行模块是位于两条水平线之间的模块子组。最小行是不能分成子行的行。 该算法首先将模块分组为最少的行,然后从左到右对每行进行排序。然后,算法将已排序的行从上到下连接起来。 有关示例,请参阅从左到右对 Simulink® 模块进行排序。 |
"topToBottom" | 使用从上到下的列按模型布局中的位置对对象进行排序。模型中的一列模块是位于两条垂直线之间的模块子组。最小列是不能分成子列的列。 该算法首先将模块分组为最小列,然后从上到下对每列进行排序。然后,算法将已排序列从左到右连接起来。 有关示例,请参阅从上到下对 Simulink® 模块进行排序。 |
"runtime" | 仅对包含 |
输出参量
sortedList
— 排序列表
字符串数组 | 句柄数组 | 搜索结果对象数组
排序列表,以字符串数组、句柄数组或搜索结果对象数组的形式返回。返回的数组与 unsortedList
类型相同。
版本历史记录
在 R2022b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)