Main Content

slreportgen.utils.sortSystems

Sort Simulink systems

Since R2022b

Description

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.

example

Examples

collapse all

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

Import these namespaces so you do not have to use 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";
open_system(model_name);

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));
disp([sysList.Path]');
    "sortSystemsExampleModel"
    "sortSystemsExampleModel/System1"
    "sortSystemsExampleModel/System2"
    "sortSystemsExampleModel/System3"
    "sortSystemsExampleModel/System4"

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");
disp([sortedList.Path]');
    "sortSystemsExampleModel/System4"
    "sortSystemsExampleModel/System1"
    "sortSystemsExampleModel/System3"
    "sortSystemsExampleModel"
    "sortSystemsExampleModel/System2"

Input Arguments

collapse all

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

Example: slreportgen.utils.sortSystems(["f14","sf_car","sldemo_fuelsys"])

Example: slreportgen.utils.sortSystems(find_system("f14",findall=true,type="block",blocktype="SubSystem"))

Example: slreportgen.utils.sortSystems([find(slreportgen.finder.DiagramFinder("sf_car")),find(slreportgen.finder.DiagramFinder("sldemo_fuelsys"))])

Method for sorting, specified as one of these values:

  • "alphabetical" — Sort objects alphabetically by name.

  • "numBlocks" — Sort systems by the number of blocks in the system, from large to small. For an example, see Sort Simulink® Systems by Number of Blocks.

  • "depth" — Sort systems by depth in the model hierarchy, where subsystems precede the subsystems they contain.

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