Data Type Mismatch and Structure Initial Conditions

Specify Bus Signal Initial Conditions Using Simulink.Parameter Objects

This example shows how to replace a structure initial condition with a Simulink.Parameter object. This approach allows the structure to maintain its tunability.

  1. Double-click the Unit Delay block to view the block parameters. The Unit Delay block uses a structure initial condition.

  2. Define a Simulink.Parameter object at the MATLAB® command line. Set the data type of the parameter object to the bus object SensorData. Set the value of the parameter object to the specified structure. To maintain tunability, set the StorageClass property to ExportedGlobal.

    P = Simulink.Parameter;
    P.DataType = 'Bus: SensorData';
    P.Value = struct('Torque',5,'Speed',8);
    P.StorageClass = 'ExportedGlobal';

  3. In the Unit Delay block dialog box, set Initial condition to P, the Simulink.Parameter object you defined. The structure defined in the Simulink.Parameter object remains tunable.

For more information on generating code for bus signals that use tunable initial condition structures, see Control Signal and State Initialization in the Generated Code (Simulink Coder).

Data Type Mismatch and Masked Atomic Subsystems

A data type mismatch occurs when a structure initial condition drives a bus signal that you specified using a masked atomic subsystem.

Change the subsystem to non atomic, or specify the structure parameter using a Simulink.Parameter object (as described in Specify Bus Signal Initial Conditions Using Simulink.Parameter Objects) to avoid the data type mismatch error.

Related Topics