slreportgen.utils.sortObjects
Syntax
Description
sorts the elements in sortedList
= slreportgen.utils.sortObjects(objectList
)objectList
alphabetically by name. You must load
the models that contain the objects before using the sortObjects
function. The function ignores and excludes invalid elements.
uses sortedList
= slreportgen.utils.sortObjects(objectList
,sortMethod
)sortMethod
to sort the elements in
objectList
.
Examples
Sort Simulink Objects by Depth
This example shows how to use the slreportgen.utils.sortObjects
function to sort Simulink objects by depth.
Import these namespaces so you do not have to use long, fully qualified function and class names.
import slreportgen.finder.* import slreportgen.utils.*
Load the Simulink model sortByDepthExampleModel
.
model_name = "sortByDepthExampleModel";
load_system(model_name)
Use an slreportgen.finder.DiagramFinder
object to find all the systems in the model, including the model itself. Then create an empty slreportgen.finder.BlockResult
array.
sysArray = find(DiagramFinder(model_name)); unsortedList = BlockResult.empty;
Iterate through sysArray
and use an slreportgen.finder.BlockFinder
object to search for blocks in each subsystem. For each subsystem, append the search result block array to the end of the unsortedList
array.
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
Display the paths of the blocks in unsortedList
to see how they are sorted.
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"
Use the slreportgen.utils.sortObjects
function to sort the blocks in unsortedList
by depth. Then display the paths of the sorted blocks to verify they are sorted by depth.
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"
Input Arguments
objectList
— List of objects to sort
string array | handle array | search result object array
Run the following command to access the supporting files used in this example.
openExample('rptgenext/SimulinkReportGeneratorFilesExample');
List of Simulink® and Stateflow® objects to sort, specified as one of these values:
Value | Example |
---|---|
String array of model names and block paths |
objectList = ["f14",... "f14/Actuator Model",... "f14/Aircraft Dynamics Model",... "sf_car",... "slrgex_fuelsys",... "slrgex_radar_eml"]; |
Array of model and block handles |
load_system("f14"); objectList = find_system("f14",findall=true); |
Search result object array, returned by
DiagramElementFinder , BlockFinder ,
SignalFinder , and AnnotationFinder objects of
the slreportgen.finder package |
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
— Method for sorting
"alphabetical"
| "systemAlpha"
| "depth"
Method for sorting, specified as one of these values:
Value | Description |
---|---|
"alphabetical" | Sort objects alphabetically by name |
"systemAlpha" | Sort objects alphabetically by parent system name |
"depth" | Sort objects by depth in the model hierarchy, where a subsystem is preceded by the subsystem that contains it. For an example, see Sort Simulink® Objects by Depth. |
Output Arguments
sortedList
— Sorted list
string array | handle array | search result object array
Sorted list, returned as a string array, handle array, or search result object
array. The returned array is the same type as objectList
.
Version History
Introduced in R2022b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)