slreportgen.utils.sortBlocks
Syntax
Description
sorts the elements in sortedList = slreportgen.utils.sortBlocks(unsortedBlocks)unsortedBlocks alphabetically by name. You must
load the models that contain the blocks before using the sortBlocks
function. The function ignores and excludes invalid elements.
uses sortedList = slreportgen.utils.sortBlocks(unsortedBlocks,sortMethod)sortMethod to sort the elements in
unsortedBlocks.
Examples
This example shows how to use the slreportgen.utils.sortBlocks function to sort model blocks by their location in the model layout from left to right.
Import these packages so you do not have to use long, fully qualified function and class names.
import slreportgen.finder.* import slreportgen.utils.*
Open and observe the model to see how the blocks are divided to rows and how each row is sorted from left to right.
model_name = "sortLeftToRightDemoModel";
open_system(model_name);
Use an slreportgen.finder.BlockFinder object to find the block elements in the model. Save the list of blocks in the variable unsortedBlocks.
unsortedBlocks = find(BlockFinder(model_name));
Use the slreportgen.utils.sortBlocks function to sort the blocks with the sorting method leftToRight, and display the names of the sorted blocks. Verify that the blocks are sorted correctly.
sortedBlocks = sortBlocks(unsortedBlocks,"leftToRight");
disp([sortedBlocks.Name]'); "1.1"
"1.2"
"1.3"
"2.1"
"2.2"
"2.3"
"3.1"
"3.2"
"3.3"
"3.4"
"3.5"
"3.6"
"3.7"
This example shows how to use the slreportgen.utils.sortBlocks function to sort model blocks by their location in the model layout from top to bottom.
Import these namespaces so you do not have to use long, fully qualified function and class names.
import slreportgen.finder.* import slreportgen.utils.*
Open and observe the model to see how the blocks are divided to columns, and how each column is sorted from top to bottom.
model_name = "sortTopToBottomDemoModel";
open_system(model_name);
Use an slreportgen.finder.BlockFinder object to find the block elements in the model. Save the list of blocks in the variable unsortedBlocks.
unsortedBlocks = find(BlockFinder(model_name));
Use the slreportgen.utils.sortBlocks function to sort the blocks with the sorting method topToBottom, and display the names of the sorted blocks. Verify that the blocks are sorted correctly.
sortedBlocks = sortBlocks(unsortedBlocks,"topToBottom");
disp([sortedBlocks.Name]'); "1.1"
"1.2"
"1.3"
"2.1"
"2.2"
"2.3"
"3.1"
"3.2"
"3.3"
"3.4"
"3.5"
"3.6"
"3.7"
Input Arguments
List of Simulink® blocks to sort, specified as one of these values:
String array of block paths
Array of block handles
Array of search result objects returned by
slreportgen.finder.DiagramFinder,slreportgen.finder.BlockFinder, andslreportgen.finder.ChartDiagramFinderobjects
Example: slreportgen.utils.sortBlocks(["f14/Actuator Model","f14/Aircraft
Dynamics Model","f14/alpha (rad)"])
Example: slreportgen.utils.sortBlocks(find_system("f14",findall=true,type="block"))
Example: slreportgen.utils.sortBlocks([find(slreportgen.finder.DiagramFinder("f14")),find(slreportgen.finder.BlockFinder("sf_car"))])
Method for sorting, specified as one of these values:
| Value | Description |
|---|---|
"alphabetical" | Sort blocks alphabetically by name. |
"systemAlpha" | Sort blocks alphabetically by parent system name. |
"fullPathAlpha" | Sort blocks alphabetically by full block path. |
"blockType" | Sort blocks alphabetically by block type. |
"depth" | Sort blocks by depth in the model hierarchy, where subsystems precede the subsystems they contain. |
"leftToRight" | Sort objects by their location in the model layout using rows from left to right. A row of blocks in the model is a subgroup of blocks that are positioned between two horizontal lines. A minimal row is a row that cannot be divided into subrows. The algorithm first groups the blocks into minimal rows and then sorts each row from left to right. The algorithm then concatenates the sorted rows from top to bottom. For an example, see Sort Simulink® Blocks from Left to Right. |
"topToBottom" | Sort objects by their location in the model layout using columns from top to bottom. A column of blocks in the model is a subgroup of blocks that are positioned between two vertical lines. A minimal column is a column that cannot be divided into subcolumns. The algorithm first groups the blocks into minimal columns and then sorts each column from top to bottom. The algorithm then concatenates the sorted columns from left to right. For an example, see Sort Simulink® Blocks from Top to Bottom. |
"runtime" | Sort the nonvirtual blocks in the model that contains the first block
in the |
Output Arguments
Sorted list, returned as a string array, handle array, or search result object
array. The returned array is the same type as unsortedList.
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)