Skip to Main Content Skip to Search
Product Documentation

Specifying Initial Conditions for Bus Signals

Bus Signal Initialization

Bus signal initialization is a special kind of signal initialization. For general information about initializing signals, see Initializing Signals and Discrete States.

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, as described in this section, involves specifying nonzero initial conditions (ICs).

You can use bus signal initialization features to:

Blocks that Support Bus Signal Initialization

You can initialize bus signal values that input to a block, if that block meets both of these conditions:

The following blocks support bus signal initialization:

For example, the Unit Delay block is a bus-capable block and the Block Parameters dialog box for the Unit Delay block has an Initial conditions parameter.

Initialization Is Not Supported for Bus Signals with Variable-Size or Frame-Based Elements

You cannot initialize a bus that has:

Workflow for Initializing Bus Signals Using Initial Condition Structures

You need to set up your model properly to use initial condition structures to initialize bus signals. The general workflow involves the tasks listed in the following table. You can vary the order of the tasks, but before you update the diagram or run a simulation, you need to ensure your model is set up properly.

TaskDocumentation
Define an IC structureCreating Initial Condition (IC) Structures
Use an IC structure to specify a nonzero initial condition.Three Ways to Initialize Bus Signals Using Block Parameters
Set Configuration Parameters dialog box diagnosticsSetting Diagnostics to Support Bus Signal Initialization

Creating Initial Condition (IC) Structures

You can create partial or full IC structures to represent initial values for a bus signal. Create an IC structure by either:

For information about defining MATLAB structures, see Structures in the MATLAB documentation.

Full and Partial IC Structures

A full IC structure provides an initial value for every element of a bus signal. This IC structure mirrors the bus hierarchy and reflects the attributes of the bus elements.

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 of the bus signal elements, assigning 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.

Specifying full structures during code generation offers these advantages:

Match IC Structure Values to Corresponding Bus Element Data Characteristics

The field that you specify in an IC structure must match the following 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.

You must explicitly specify fields in the IC structure for every bus element that has an enumerated (enum) data type.

When you define a partial IC structure:

Examples of Partial Structures

Suppose you have a bus, Top, composed of three elements: A, B, and C, with these characteristics:

The following model, busic_example includes the nested Top bus. The screen capture below shows the model after it has been updated. (Open the model.)

The following diagram summarizes 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)

Valid partial IC structures.  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 busic_example model.

The following table shows valid initial condition specifications.

Valid SyntaxDescription
K.A.A1 = 3

Bus element Top.A.A1 is double; the corresponding structure field is 3, which is a double.

K = struct('C',struct('C1',int16(4)))

Matching data types can require you to cast types. Bus element Top.C.C1 is int16. The corresponding structure field explicitly specifies int16(4).

K = struct('B',3,'A',struct('A1',4))

Bus element Top.B and Top.A are at the same nesting level in the bus. For bus elements at the same nesting level, the order of corresponding structure fields does not matter.

Invalid partial IC structures.  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 busic_example model.

These three initial condition specifications are not valid:

Invalid SyntaxReason the Syntax Is Invalid
K.A.A2 = 3

Value data type, dimension, and complexity do not match. Top.A.A2 is an int8, but K.A.A2 is a double; Top.A.A2 is 5x1, but K.A.A2 is 1x1; Top.A.A2 is complex, but K.A.A2 is real.

K.C.C2 = 3

You cannot use a scalar to initialize IC substructures.

K = struct('B',3,'X',4)

You cannot specify fields that are not in the bus (X does not exist in the bus).

Creating Full IC Structures Using Simulink.Bus.createMATLABStruct

Use the Simulink.Bus.createMATLABStruct function to streamline the process of creating a full MATLAB initial condition structure with the same hierarchy, names, and data attributes as a bus signal. This function fills all the elements that you do not specify with the ground values for those elements.

You can use several different kinds of input with the Simulink.Bus.createMATLABStruct function, including

You can invoke the Simulink.Bus.createMATLABStruct function from the Bus Editor, using one of these approaches:

You can then edit the MATLAB structure in the MATLAB Editor.

See the Simulink.Bus.createMATLABStruct documentation for details.

Using Model Advisor to Check for Partial Structures

To detect when structure parameters are not consistent in shape (hierarchy and names) with the associated bus signal, in the Model Editor, use the Tools > Model Advisor > By Product > Simulink Check for partial structure parameter usage with bus signals check. This check identifies partial IC structures.

Three Ways to Initialize Bus Signals Using Block Parameters

You initialize a bus signal by setting the initial condition parameter for a block that receive 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 with:

All three approaches require that you define an IC structure (see Creating Initial Condition (IC) Structures). You cannot specify a nonzero scalar value or any other type of value other than 0, an IC structure, or Simulink.Parameter object to initialize a bus signal.

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:

You can tune the value of a Simulink.Parameter object during simulation.

Setting Diagnostics to Support Bus Signal Initialization

To enable bus signal initialization, before you start a simulation, set the following two Configuration Parameter diagnostics as indicated:

The documentation for these diagnostics explains how convert your model to handle error messages the diagnostics generate.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS