Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

If a block can emit nonscalar signals, the dimensions of the signals that the block outputs depend on the block parameters, if the block is a source block; otherwise, the output dimensions depend on the dimensions of the block input and parameters.

To determine the dimensions that a signal ultimately uses for simulation,
first update the block diagram (for example, by pressing
**Ctrl+D**). Then, choose one of these techniques:

Display the dimensions directly on the block diagram. Use this technique to trace signal dimensions along a path of blocks. In the model, select

**Display**>**Signals and Ports**>**Signal Dimensions**).Inspect the dimensions in the Model Data Editor, which shows you information in a searchable, sortable table. In the table, the right side of each cell in the

**Dimensions**column shows the true dimensions of the corresponding signal line in the model. For more information about the Model Data Editor, see Configure Data Properties by Using the Model Data Editor.

A *source* block is a block that has no inputs. Examples
of source blocks include the Constant block and the
Sine Wave block. See Sources for a
complete listing of Simulink^{®} source blocks. The output dimensions of a source block are the
same as those of its output value parameters if the block's **Interpret vector parameters as 1-D** parameter is
off (that is, not selected in the block parameter dialog box). If the
**Interpret vector parameters as 1-D**
parameter is on, the output dimensions equal the output value parameter
dimensions unless the parameter dimensions are N-by-1 or 1-by-N. In the
latter case, the block outputs a vector signal of width N.

As an example of how a source block's output value parameter(s) and
**Interpret vector parameters as 1-D**
parameter determine the dimensionality of its output, consider the Constant
block. This block outputs a constant signal equal to its **Constant value** parameter. The following table
illustrates how the dimensionality of the **Constant
value** parameter and the setting of the **Interpret vector parameters as 1-D** parameter
determine the dimensionality of the block's output.

Constant Value | Interpret vector parameters as 1-D | Output |
---|---|---|

scalar | off | one-element array |

scalar | on | one-element array |

1-by-N matrix | off | 1-by-N matrix |

1-by-N matrix | on | N-element vector |

N-by-1 matrix | off | N-by-1 matrix |

N-by-1 matrix | on | N-element vector |

M-by-N matrix | off | M-by-N matrix |

M-by-N matrix | on | M-by-N matrix |

Simulink source blocks allow you either to specify the dimensions of the signals that they output or specify values from which Simulink infers the dimensions. You can therefore use the source blocks to introduce signals of various dimensions into your model.

If a block has inputs, the dimensions of its outputs are, after scalar expansion, the same as those of its inputs. (All inputs must have the same dimensions, as discussed in Signal and Parameter Dimension Rules).

When creating a Simulink model, you must observe the following rules regarding signal and parameter dimensions.

All nonscalar inputs to a block must have the same dimensions.

A block can have a mix of scalar and nonscalar inputs as long as all the nonscalar inputs have the same dimensions. Simulink expands the scalar inputs to have the same dimensions as the nonscalar inputs (see Scalar Expansion of Inputs and Parameters).

In general, block parameters must have the same dimensions as the dimensions of the inputs to the block. Simulink performs some processing that provides flexibility relating to that general rule.

A block can have scalar parameters corresponding to nonscalar inputs. In this case, Simulink expands a scalar parameter to have the same dimensions as the corresponding input (see Scalar Expansion of Inputs and Parameters).

If an input is a vector, the corresponding parameter can be either an N-by-1 or a 1-by-N matrix. In this case, Simulink applies the N matrix elements to the corresponding elements of the input vector. This exception allows use of MATLAB

^{®}row or column vectors, which are actually 1-by-N or N-by-1 matrices, respectively, to specify parameters that apply to vector inputs.

Simulink converts vectors to row or column matrices and row or column matrices to vectors under the following circumstances:

If a vector signal is connected to an input that requires a matrix, Simulink converts the vector to a one-row or one-column matrix.

If a one-column or one-row matrix is connected to an input that requires a vector, Simulink converts the matrix to a vector.

If the inputs to a block consist of a mixture of vectors and matrices and the matrix inputs all have one column or one row, Simulink converts the vectors to matrices having one column or one row, respectively.

### Note

You can configure Simulink to display a warning or error message if a vector or matrix conversion occurs during a simulation. See Vector/matrix block input conversion for more information.

*Scalar expansion* is the
conversion of a scalar value into a nonscalar array. Many Simulink blocks support scalar expansion of inputs and parameters.
Block-specific descriptions indicate whether Simulink applies scalar expansion to a block's inputs and
parameters.

Scalar expansion of inputs refers to the expansion of scalar inputs to match the dimensions of other nonscalar inputs or nonscalar parameters. When the input to a block is a mix of scalar and nonscalar signals, Simulink expands the scalar inputs into nonscalar signals having the same dimensions as the other nonscalar inputs. For example, a scalar of 4 is expanded to the vector [4 4 4] if the associated nonscalar has a dimension of 3.

Scalar expansion of parameters refers to the expansion of scalar block parameters to match the dimensions of nonscalar inputs.

Input(s) | Associated Block Parameter | Scalar Expansion |
---|---|---|

Scalar | Nonscalar | Input expanded to match parameter dimensions. |

Nonscalar | Scalar | Scalar parameter expanded to match number of elements of input. |

Combination of scalar and nonscalar | No corresponding parameter | Scalar inputs expanded to match dimensions of largest nonscalar input. See Scalar and Nonscalar Inputs and No Associated Parameter. |

In this example, the Constant block input to the Gain block is scalar.
The Gain block **Gain** parameter is a nonscalar.
Simulink expands the scalar input to match the dimensions of a
nonscalar **Gain** parameter, as reflected in the
simulation results in the Display block.

In this example, the Constant block input to the Gain block is
nonscalar. The Gain block **Gain** parameter is a
scalar. Simulink expands the scalar parameter to match the dimensions of
a nonscalar input from the Constant block, as reflected in the
simulation results in the Display block.

In this example, the Constant1 block input to the Sum block is
nonscalar, and the Constant2 block input is scalar. The Sum block has
no associated parameter. Simulink expands the scalar input from Constant2 to match to the
dimensions of the nonscalar Constant1 block input. The input is
expanded to the vector `[3 3 3]`

.

To get the dimensions of port signals, pause the simulation by using
the **Step Forward** button. Select a block and use
the `PortHandles`

parameter. Then use the
`GetCompiledPortDimensions`

parameter. For
example, if you step forward in this model and select the
Constant block:

ph = get_param(gcb,'PortHandles'); dim = get_param(ph.Outport,'CompiledPortDimensions')

dim = 2 2 3

For nonbus ports, the result is an array in which the first element is
the number of dimensions (in this case `2`

), and the
next two elements (corresponding to the number of dimensions) are the
values of the dimensions.

For bus signals, the results include some extra elements. Suppose that you step forward in a model with buses and you select the Bus Creator block that contains a nested bus:

ph = get_param(gcb,'PortHandles'); dim = get_param(ph.Outport,'CompiledPortDimensions')

dim = -2 4 1 2 1 1 3 4 5 6 5 2 3 4 5 6

The first element is `-2`

, which indicates that the
signal is a bus. The second element is the number of leaf nodes. The
subsequent elements follow the same pattern as for nonbus signals. In
this example, the third element represents the number of dimensions
for the first signal in the bus (in this case `1`

),
and the next number is the value in that dimension
(`2`

).