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
Sort Simulink Blocks from Left to Right
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"
Sort Simulink Blocks from Top to Bottom
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
unsortedBlocks
— List of blocks 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® blocks to sort, specified as one of these values:
Value | Example |
---|---|
String array of block paths |
unsortedBlocks = ["f14/Actuator Model",... "f14/Aircraft Dynamics Model",... "f14/alpha (rad)"]; |
Array of block handles |
load_system("f14"); unsortedList = find_system("f14",... findall=true,type="block"); |
Search result object array, returned by DiagramFinder ,
BlockFinder , and ChartDiagramFinder objects of
the slreportgen.finder package |
import slreportgen.finder.* load_system("sf_car"); load_system("f14"); diagFinder = DiagramFinder("f14"); blockFinder = BlockFinder("sf_car"); unsortedBlocks = [find(diagFinder),find(blockFinder)]; |
sortMethod
— Method for sorting
"alphabetical"
| "systemAlpha"
| "fullPathAlpha"
| "blockType"
| "depth"
| "leftToRight"
| "topToBottom"
| "runtime"
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 a subsystem is preceded by the subsystem that contains it. |
"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 to subrows. The algorithm first groups the blocks to minimal rows and 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 to minimal columns and 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 only the nonvirtual blocks in model that contains the first
block in the |
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 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.
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 (한국어)