This example shows how to replace a structure initial condition with a
Simulink.Parameter
object. This approach allows the structure
to maintain its tunability.
Double-click the Unit Delay block to view the block parameters. The Unit Delay block uses a structure initial condition.
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';
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.
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.