slreportgen.utils.sortObjects
语法
说明
按名称字母顺序对 sortedList
= slreportgen.utils.sortObjects(objectList
)objectList
中的元素进行排序。在使用 sortObjects
函数之前,您必须加载包含对象的模型。该函数忽略并排除无效元素。
使用 sortedList
= slreportgen.utils.sortObjects(objectList
,sortMethod
)sortMethod
对 objectList
中的元素进行排序。
示例
按深度对 Simulink 对象进行排序
此示例显示如何使用 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"
输入参数
objectList
— 要排序的对象列表
字符串数组 | 句柄数组 | 搜索结果对象数组
运行以下命令访问本示例中使用的支持文件。
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 包中的 DiagramElementFinder 、BlockFinder 、SignalFinder 、AnnotationFinder 对象返回 | import slreportgen.finder.* load_system("sf_car"); load_system("slrgex_fuelsys"); blockFinder = BlockFinder("sf_car"); sigFinder = SignalFinder("slrgex_fuelsys"); objectList = [find(blockFinder) find(sigFinder)]; |
sortMethod
— 排序方法
"alphabetical"
| "systemAlpha"
| "depth"
排序方法,指定为以下值之一:
值 | 描述 |
---|---|
"alphabetical" | 按名称的字母顺序对对象进行排序 |
"systemAlpha" | 按父系统名称的字母顺序对对象进行排序 |
"depth" | 按模型层次结构的深度对对象进行排序,其中一个子系统位于包含它的子系统之前。有关示例,请参阅按深度对 Simulink® 对象进行排序。 |
输出参量
sortedList
— 排序列表
字符串数组 | 句柄数组 | 搜索结果对象数组
排序列表,以字符串数组、句柄数组或搜索结果对象数组的形式返回。返回的数组与 objectList
类型相同。
版本历史记录
在 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)