Bus signal initialization is a special form of signal initialization. For general information about initializing signals, see Initialize Signals and Discrete States. For details about initializing array of buses signals, see Initialize Arrays of Buses.
Bus signal initialization specifies the bus element values that Simulink® uses for the first execution of a block that uses that bus signal. By
default, the initial value for a bus element is the ground value (represented by
0). Bus initialization involves specifying nonzero initial
You can use bus signal initialization features to:
Specify initial conditions for signals that have different data types.
Apply a different initial condition for each signal in the bus.
Specify initial conditions for a subset of signals in a bus without specifying initial conditions for all the signals.
Use the same initial conditions for multiple blocks, signals, or models.
You can initialize bus signal values that input to a block if that block meets both of these conditions:
Has an initial value or initial condition block parameter
Supports bus signals
These blocks support bus signal initialization:
Data Store Memory
Outport (when the block is inside a conditionally executed context)
For example, the Unit Delay block is a bus-capable block. Its Block Parameters dialog box has an Initial conditions parameter.
You cannot initialize a bus that has:
To enable bus signal initialization, before you start a simulation, set the Underspecified initialization detection configuration parameter to
You can create partial or full initial condition (IC) structures to represent initial values for a bus signal. To create an IC structure, use one of these approaches:
Define a MATLAB® structure in the MATLAB base or Simulink model workspace. You can manually define the structure, or
alternatively for full structures, you can use the
In the Block Parameters dialog box for a block that supports bus signal initialization, for the initial condition parameter specify an expression that evaluates to a structure.
For information about defining MATLAB structures, see Create Structure Array (MATLAB).
The field that you specify in an IC structure must match these data attributes of the bus element exactly:
For example, if you define a bus element to be a real [2x2] double array, then in the IC structure, define the value to initialize that bus element to be a real [2x2] double array.
Explicitly specify fields in the IC structure for every bus element that has an
enum) data type.
If any of the signal elements of the target bus use a data type other than
double, you can use different techniques to control the data
types of the fields of initial condition structures. The technique that you choose
can influence the efficiency and readability of the generated code. See Control Data Types of Initial Condition Structure Fields.
A full initial condition structure provides an initial value for every element of a bus signal. The IC structure mirrors the bus hierarchy and reflects the attributes of the bus elements.
Specifying full structures during code generation offers these advantages:
Generates more readable code
Supports a modeling style that explicitly initializes all signals
function to streamline the creation of a full MATLAB initial condition structure
with the same hierarchy, names, and data attributes as a bus signal. This function
fills all of the elements that you do not specify with ground values for those
You can use several different kinds of input with the function, including:
A bus object name
An array of port handles
You can invoke the function from the Bus Editor. Select the bus object for which you want to create a a full MATLAB structure, and then select the File > Create a MATLAB structure menu item.
To detect when structure parameters are not consistent in shape (hierarchy and names) with the associated bus signal, in the Simulink Editor, use the Analysis > Model Advisor > By Product > Simulink Check structure parameter usage with bus signals check. This check identifies partial IC structures.
After you create the structure, you can edit it in the MATLAB Editor.
A partial IC structure provides initial values for a subset of the elements of a bus signal. If you use a partial IC structure, during simulation, Simulink creates a full IC structure to represent all the bus signal elements. Simulink assigns the respective ground value to each element for which the partial IC structure does not explicitly assign a value.
Specifying partial structures for block parameter values can be useful during the iterative process of creating a model. Partial structures enable you to focus on a subset of signals in a bus. When you use partial structures, Simulink initializes unspecified signals implicitly.
When you define a partial IC structure:
Include only fields that are in the bus.
Omit one or more fields that are in the bus.
Make the field in the IC structure correspond to the nesting level of the bus element.
Within the same nesting level in both the structure and the bus, optionally specify the structure fields in a different order than the bus elements.
The value of an IC structure must lie within the design minimum and maximum range of the corresponding bus element. Simulink performs this range checking when you do an update diagram or simulate the model.
Suppose that you have a bus,
Top, composed of three elements:
C, with these
A is a nested bus, with two signal elements.
B is a single signal.
C is a nested bus that includes bus
A as a nested bus.
ex_busic model includes the nested
bus. This is how the model appears after it has been updated.
Open the model.
Here is a summary of the
Top bus hierarchy and the data type,
dimension, and complexity of the bus elements.
Top A (sub1) A1 (double) A2 (int8, 5x1, complex) B (double) C (sub2) C1 (int16) C2 (sub1) A1 (double) A2 (int8, 5x1, complex)
In these examples,
K is an IC structure specified for the
initial value of the Unit Delay block. The IC structure corresponds
Top bus in the
ex_busic model. Here are
some valid initial condition specifications.
Initialize the bus element
The bus element
In the following examples,
K is an IC structure specified
for the initial value of the Unit Delay block. The IC structure
corresponds to the
Top bus in the
These three initial condition specifications are not valid:
|Invalid Syntax||Reason the Syntax Is Invalid|
Value dimension and complexity do not match. The bus
You cannot use a scalar value to initialize IC substructures.
You cannot specify fields that are not in the bus
Initialize a bus signal by setting the initial condition parameter for a block that receives a bus signal as input and that supports bus initialization (see Blocks That Support Bus Signal Initialization).
For example, the Block Parameters dialog box for the Unit Delay block has an Initial conditions parameter.
For a block that supports bus signal initialization, you can
replace the default value of
0 using one of these
All three approaches require that you define an IC structure (see Create Initial Condition Structures). You cannot specify a nonzero
scalar value or any other type of value other than
0, an IC
Simulink.Parameter object to initialize a bus
Defining an IC structure as a MATLAB variable, rather than specifying the IC structure directly in the Block Parameters dialog box offers several advantages, including:
Reuse of the IC structure for multiple blocks
Using the IC structure as a tunable parameter in the generated code
You can initialize a bus signal using a MATLAB structure that explicitly defines the initial conditions for the bus signal.
For example, in the Initial conditions parameter of the Unit Delay block, you could type in a structure.
You can initialize a bus signal using a MATLAB variable that you define as an IC structure with the appropriate values.
For example, you could define the following partial structure in the base workspace:
K = struct('A', struct('A1', 3), 'B', 4);
You can then specify the
K structure as the Initial
conditions parameter of the Unit Delay block:
You can initialize a bus signal using a
Simulink.Parameter object that
uses an IC structure for the
For example, you could define the partial structure
the base workspace (reflecting the
ex_busic model discussed
in the previous section):
P = Simulink.Parameter; P.DataType = 'Bus: Top'; P.Value = Simulink.Bus.createMATLABStruct('Top'); P.Value.A.A1 = 3; P.Value.B = 5;
You can then specify the
P structure as the
Initial conditions parameter of the Unit Delay