| Simulink® | ![]() |
| On this page… |
|---|
The sorted order is an ordering of the blocks in the model that Simulink® uses as a starting point for determining the order in which to invoke the blocks' methods (see Block Methods) during simulation. Simulink allows you to display the sorted order for a model and to assign priorities to blocks that can influence where they appear in the sorted order.
Simulink uses the following basic rules to sort the blocks:
Each block must appear in the sorted order ahead any of the blocks whose direct-feedthrough ports (see About Direct-Feedthrough Ports) it drives.
This rule ensures that the direct-feedthrough inputs to blocks will be valid when block methods that require current inputs are invoked.
Blocks that do not have direct feedthrough inputs can appear anywhere in the sorted order as long as they precede any blocks whose direct-feedthrough inputs they drive.
Putting all blocks that do not have direct-feedthrough ports at the head of the sorted order satisfies this rule. It thus allows Simulink to ignore these blocks during the sorting process.
The result of applying these rules is a sorted order in which blocks without direct feedthrough ports appear at the head of the list in no particular order followed by blocks with direct-feedthrough ports in the order required to supply valid inputs to the blocks they drive.
During the sorting process, Simulink checks for and flags the occurrence of algebraic loops, that is, signal loops in which a direct-feedthrough output of a block is connected directly or indirectly to the corresponding direct-feedthrough input of the block. Such loops seemingly create a deadlock condition, because the block needs the value of the direct-feedthrough input to compute its output.
However, an algebraic loop can represent a set of simultaneous algebraic equations (hence the name) where the block's input and output are the unknowns. Further, these equations can have valid solutions at each time step. Accordingly, Simulink assumes that loops involving direct-feedthrough ports do, in fact, represent a solvable set of algebraic equations and attempts to solve them each time the block's output is required during a simulation. For more information, see Algebraic Loops.
In order to ensure that the sorted order reflects data dependencies among blocks, Simulink categorizes a block's input ports according to the dependency of the block's outputs on its inputs. An input port whose current value determines the current value of one of the block's outputs is called a direct-feedthrough port. Examples of blocks that have direct-feedthrough ports include the Gain, Product, and Sum blocks. Examples of blocks that have non-direct-feedthrough inputs include the Integrator block (its output is a function purely of its state), the Constant block (it does not have an input), and the Memory block (its output is dependent on its input in the previous time step).
To display the sorted order, select Format > Block Displays > Sorted Order from the Simulink menu. Selecting this option causes Simulink to display a notation in the top right corner of each block in a block diagram.

The notation for most blocks has the format s:b, where s specifies the index of the subsystem to whose execution context (see Conditional Execution Behavior) the block belongs and b specifies the block's position in the sorted order for that execution context.
The sorted order of a Function-Call Subsystem cannot be determined at compile time. For these subsystems, Simulink therefore uses either the notation s:F, if the system has one initiator, where s is the index of the subsystem that contains the initiator; or the notation M, if the subsystem has more than one initiator.
A bus-capable block does not execute as a unit, and therefore does not have a unique sorted order. Such a block displays its sorted order as s:B. See Bus-Capable Blocks for more information.
A virtual block, such as the Mux block in the preceding figure, exists only graphically. Virtual blocks do not execute, so they are not part of a model's sorted order and do not display any sorted order notation.
You can assign priorities to nonvirtual blocks or virtual subsystem blocks in a model (see Virtual Blocks). Higher priority blocks appear before lower priority blocks in the sorted order, though not necessarily before blocks that have no assigned priority.
You can assign block priorities interactively or programmatically. To set priorities programmatically, use the command
set_param(b,'Priority','n')
where b is a block path and n is any valid integer. (Negative numbers and 0 are valid priority values.) The lower the number, the higher the priority; that is, 2 is higher priority than 3. To set a block's priority interactively, enter the priority in the Priority field of the block's Block Properties dialog box (see Block Properties Dialog Box).
Simulink honors the block priorities that you specify only if they are consistent with the Simulink block sorting algorithm. If Simulink is unable to honor a block priority, it displays a Block Priority Violation diagnostic message (see Diagnostics Pane: Solver).
![]() | Displaying Block Outputs | Accessing Block Data During Simulation | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |