Main Content


Sort Simulink and Stateflow systems

Since R2022b


sortedList = slreportgen.utils.sortSystems(systemList) sorts the elements in systemList alphabetically by name. You must load the models containing the systems before using the sortSystems function. The function ignores and excludes invalid elements.


sortedList = slreportgen.utils.sortSystems(systemList,sortMethod) uses sortMethod to sort the elements in systemList.


collapse all

This example shows how to use the slreportgen.utils.sortSystems function to sort Simulink systems by the number of blocks.

Import these namspaces so you do not have to use long, fully qualified function and class names.

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

Open the model and note how many blocks each subsystem contains.

model_name = "sortSystemsExampleModel";

Use an slreportgen.finder.DiagramFinder object to find and create a list of the systems in the model. Display the paths of the systems and note that the model itself is considered a system.

sysList = find(DiagramFinder(model_name));

Use the slreportgen.utils.sortSystems function to sort the systems by the number of blocks. Display the paths of the sorted list and note that the numBlocks sort option considers subsystems as blocks.

sortedList = sortSystems(sysList,"numBlocks");

Input Arguments

collapse all

Run the following command to access the supporting files used in this example.


List of Simulink® and Stateflow® systems to sort, specified as one of these values:

String array of model names
systemList = ["slrgex_f14",...
Array of system handles

systemList = find_system("slrgex_f14",findall=true,...
slreportgen.finder.DiagramResult array returned by slreportgen.finder.DiagramFinder objects
import slreportgen.finder.*


finder1 = DiagramFinder("sf_car");
finder2 = DiagramFinder("slrgex_fuelsys");

systemList = [find(finder1) find(finder2)];

Method for sorting, specified as one of these values:


Sort objects alphabetically by name.


Sort systems by the number of blocks in the system, from large to small.


Sort objects by depth in the model hierarchy, where a subsystem is preceded by the subsystem that contains it.

Output Arguments

collapse all

Sorted list, returned as a string array, handle array, or slreportgen.finder.DiagramResult object array. The returned array is the same type as systemList.

Version History

Introduced in R2022b