Main Content

Simulink Decision Count

R2026b
Since R2022b

Metric ID

slcomp.SimulinkDecisions

Description

Use this metric to count the number of Simulink® decisions in the Simulink blocks in each layer of a unit or component.

Supported Artifacts

You can collect this metric for Units and Components. To control what the dashboard classifies as a unit or component, see Categorize Models in Hierarchy as Components or Units.

Decision Counts for Common Block Types

The following table shows how the metric calculates the decision count for common Simulink blocks.

Block or EntityDecision CountDescription
Abs1

For the decision count, the Abs block can be treated as an if-else statement:

  • If the input to the Abs block is less than zero, the output of the Abs block is the input multiplied by negative 1.

  • Otherwise, by default, the output of the Abs block is equal to the input of the Abs block.

if (input < 0)
  % one decision
  output = -1*input;
else
  % default path
  % zero decisions
  output = input;
end

An if-else statement has a decision count of 1 because the if statement represents one decision and the else statement represents the default behavior (no decisions made).

Combinatorial LogicNumber of rows in the Truth table parameter minus 1

The decision count depends on the number of rows in the truth table.

If a truth table contains five rows, the decision count is 4. One row in the truth table contains the default output and the other four rows contain potential outputs that depend on a decision being made.

Note

The metric expects that you specify the truth table directly inside the Combinatorial Logic block and that you specify the Truth table parameter by using a matrix that defines all possible block outputs. If the metric is unable to parse the matrix, the metric returns a decision count of 1.

Dead Zone2

The output of the Dead Zone block depends on the block input (U) and the values of the Start of dead zone(lower limit, LL) and End of dead zone (upper limit, UL) parameters.

For the decision count, the Dead Zone block can be treated as an if-elseif-else statement:

  • If U >= LL and U <= UL, the output is 0.

  • If U > UL, the output is U - UL.

  • Otherwise, the output is U - LL.

if ((U >= LL) & (U <= UL))
  % one decision
  output = 0;
elseif (U > UL)
  % one decision
  output = U - UL;
else
  % default path
  % zero decisions
  output = U - LL;
end

An if-elseif-else statement has a decision count of 2 because the if statement represents one decision, the elseif statement represents one decision, and the else statement represents the default behavior (no decisions made).

DelayEither 0, 1, or 2

The decision count depends on the Show enable port parameter and the External reset parameter.

  • If you clear the Show enable port check box and you set External reset to None, the decision count is 0.

  • If you select Show enable port and you set External reset to None, the decision count is 1.

  • If you clear the Show enable port check box and you set External reset to a value other than None, the decision count is 1.

  • If you select Show enable port and you set External reset to a value other than None, the decision count is 2.

Discrete-Time IntegratorEither 0, 1, 2, or 3

The decision count depends on the External reset parameter and the Limit output parameter.

  • If you set External reset to none and you clear the Limit output check box, the decision count is 0. This is the default behavior for the Discrete-Time Integrator block.

  • If you set External reset to a value other than none and you clear the Limit output check box, the decision count is 1.

  • If you set External reset to none and you select Limit output, the decision count is 2.

  • If you set External reset to a value other than none and you select Limit output, the decision count is 3.

Discrete FilterEither 0 or 1

The decision count depends on the External reset parameter.

  • If External reset is set to None, the decision count is 1.

  • Otherwise, the decision count is 0.

Discrete FIR FilterEither 0, 1, or 2

The decision count depends on the Show enable port parameter and the External reset parameter.

  • If you clear the Show enable port check box and you set External reset to None, the decision count is 0.

  • If you select Show enable port and you set External reset to None, the decision count is 1.

  • If you clear the Show enable port check box and you set External reset to a value other than None, the decision count is 1.

  • If you select Show enable port and you set External reset to a value other than None, the decision count is 2.

Enabled and Triggered Model or Subsystem1

For the decision count, a model or subsystem that is enabled and triggered can be treated as an if-else statement:

  • If the model or subsystem is enabled and triggered, the model or subsystem executes.

  • Otherwise, by default, the model or subsystem does not execute.

An if-else statement has a decision count of 1 because the if statement represents one decision and the else statement represents the default behavior (no decisions made).

Enabled Model or Subsystem1

For the decision count, a model or subsystem that is enabled can be treated as an if-else statement:

  • If the model or subsystem is enabled, the model or subsystem executes.

  • Otherwise, by default, the model or subsystem does not execute.

An if-else statement has a decision count of 1 because the if statement represents one decision and the else statement represents the default behavior (no decisions made).

For Iterator Subsystem1

For the decision count, the For Iterator Subsystem block can be treated as an if-else statement:

  • If the iteration value is less than or equal to the iteration limit, iterate over blocks in the For Iterator Subsystem block.

  • Otherwise, the subsystem does not execute.

An if-else statement has a decision count of 1 because the if statement represents one decision and the else statement represents the default behavior (no decisions made).

IfNumber of if and elseif expressions

Each if statement represents a decision and each elseif statement represents a decision.

The decision count is the number of if and elseif statements.

For example, the following code contains one if statement and one elseif statement and therefore has a decision count of 2:

if (u > 0) % one decision
  y = 1;
elseif (u < 0) % one decision
  y = 2;
else % default path, zero decisions
  y = 0;
end

Index Vector1

The Index Vector block is associated with a decision count of 1.

The Index Vector block is a special configuration of the Multiport Switch block in which you specify one data input and the control input is zero-based.

For example, if the input vector is [18 15 17 10] and the control input is 3 (zero-based index), the output is 10. Using the control input to index into the input vector is considered a single decision.

MinMaxEither 1 or the number of input ports minus 1

The decision count depends on the number of input ports:

  • If the number of input ports is 1, then the decision count is 1.

  • Otherwise, the decision count is the number of input ports minus 1.

Multiport SwitchNumber of data ports minus 1

The decision count for the Multiport Switch block depends on the number of data ports that are inputs to the block. The number of data ports represents the number of possible outcomes.

The decision count is the number of data ports minus 1 because one of the possible outcomes is the default path. For the default path, no decision was made.

For example, if the number of data inputs is 3, then the decision count is 2.

If there is only one data port, the Multiport Switch block acts as an Index Vector block and has a decision count of 1.

Rate Limiter2

The output of the Rate Limiter block is determined by comparing rate to the Rising slew rate (R) and Falling slew rate (F) parameters.

For the decision count, the Rate Limiter block can be treated as an if-elseif-else statement:

  • If rate is greater than R, the output is calculated using the rising slew rate.

  • If rate is less than F, the output is calculated using the falling slew rate.

  • Otherwise, the rate is between the bounds of R and F and the change in output is equal to the change in input.

An if-elseif-else statement has a decision count of 2 because the if statement represents one decision, the elseif statement represents one decision, and the else statement represents the default behavior (no decisions made).

Relay2

The output of the Relay block is determined by the Switch off point and the Switch on point parameters.

For the decision count, the Relay block can be treated as an if-elseif-else statement:

  • If the relay is on, the output remains on until the input drops below the value of the Switch off point parameter.

  • If the relay is off, the output remains off until the input exceeds the value of the Switch on point parameter.

  • Otherwise, the input falls between the Switch off point and the Switch on point and the output is unchanged.

An if-elseif-else statement has a decision count of 2 because the if statement represents one decision, the elseif statement represents one decision, and the else statement represents the default behavior (no decisions made).

Saturation2

The output of the Saturation block is determined by comparing the input to the Upper limit and Lower limit parameters.

For the decision count, the Saturation block can be treated as an if-elseif-else statement:

  • If the input is less than the Lower limit, the output is the value of the Lower limit.

  • If the input is greater than the Upper limit, the output is the value of the Upper limit.

  • Otherwise, the output is the value of the input.

An if-elseif-else statement has a decision count of 2 because the if statement represents one decision, the elseif statement represents one decision, and the else statement represents the default behavior (no decisions made).

SendEither 0 or 1

The decision count depends on the Show enable port parameter.

  • If you clear the Show enable port check box, the decision count is 0.

  • If you select Show enable port, the decision count is 1.

Sign2

The output of the Sign block is determined by the input.

For the decision count, the Sign block can be treated as an if-elseif-else statement:

  • If the input is negative, the output is negative 1.

  • If the input is positive, the output is positive 1.

  • Otherwise, the output is 0.

An if-elseif-else statement has a decision count of 2 because the if statement represents one decision, the elseif statement represents one decision, and the else statement represents the default behavior (no decisions made).

Switch1

The Switch block is associated with a decision count of 1:

  • If input 2 (the control input) satisfies the selected criterion, the output is equal to input 1.

  • Otherwise, the output is equal to input 3.

For example, the following code shows a decision count of 1:

switch (u2 > 0)
  case 1 % one decision
    y = u1;
  otherwise % default path, zero decisions
    y = u3;
end

Switch CaseNumber of outports minus 1

The default case represents the default behavior (no decisions made). But each subsequent case represents a decision.

The decision count is the number of outports minus 1.

For example, the following code represents a Switch Case block with 3 outputs and has a decision count of 2:

switch u1
  case 1 % one decision
    y = port1;
  case 2 % one decision
    y = port2;
  otherwise % default path, zero decisions
    y = port3;
end

Triggered Model or Subsystem1

For the decision count, a model or subsystem that is triggered can be treated as an if-else statement:

  • If the model or subsystem is triggered, the model or subsystem executes.

  • Otherwise, by default, the model or subsystem does not execute.

An if-else statement has a decision count of 1 because the if statement represents one decision and the else statement represents the default behavior (no decisions made).

Trigonometric Function0 or 3

The decision count depends on the Function parameter and the Remove protection against out-of-range input parameter.

  • If you set the Function parameter to asin or acos and you clear the Remove protection against out-of-range input checkbox, the decision count is 3.

  • Otherwise, the decision count is 0.

While Iterator Subsystem1

For the decision count, the While Iterator Subsystem block can be treated as an if-else statement:

  • If the value of the input condition is true or 1, execute the contents of the subsystem.

  • Otherwise, the subsystem does not execute.

An if-else statement has a decision count of 1 because the if statement represents one decision and the else statement represents the default behavior (no decisions made).

Computation Details

The metric is a heuristic that estimates the number of Simulink decisions. The calculated decision count is not exact.

The metric:

  • Includes active and inactive variants in the decision count.

  • Does not include commented blocks in the decision count.

  • Does not compile the model. The metric only considers static information.

  • Does not resolve parameters. For example, if you specify a block parameter using a variable, the metric does not resolve the parameter to the variable value because that would require the metric to compile the model.

The metric aligns with the decision coverage returned by Simulink Coverage™. For information, see Model Objects That Receive Coverage (Simulink Coverage).

Collection

To collect data for this metric, use getMetrics with the metric identifier slcomp.SimulinkDecisions.

Results

For this metric, instances of metric.Result return Value as the number of Simulink decisions in the Simulink blocks in each layer of a unit or component.

Examples

To see the number of Simulink decisions associated with different block types, see Decision Counts for Common Block Types.

See Also

Objects

Functions

Topics