Main Content

slreportgen.utils.sortSystems

Sort Simulink and Stateflow 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

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

openExample('rptgenext/SimulinkReportGeneratorFilesExample');

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

ValueExample
String array of model names
systemList = ["f14",...
              "sf_car",...
              "slrgex_fuelsys",...
              "slrgex_radar_eml"];
Array of system handles
load_system("f14");

systemList = find_system("f14",findall=true,...
                  type="block",blocktype="SubSystem");
slreportgen.finder.DiagramResult array returned by slreportgen.finder.DiagramFinder objects
import slreportgen.finder.*

load_system("f14");
load_system("sf_car");

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

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

Method for sorting, specified as one of these values:

ValueDescription
"alphabetical"

Sort objects alphabetically by name.

"numBlocks"

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

"depth"

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