Main Content

Simulink.Signal

Specify instance-specific properties of signal or discrete state

Description

This object enables you to create workspace objects that you can use to assign or validate the attributes of a signal or discrete state, such as its data type, numeric type, dimensions, and so on.

You can use a signal object to:

  • Assign values to signal attributes that are left unassigned (have a value of -1 or auto) by the signal source.

  • Validate signal attributes whose values are explicitly assigned by the signal source. Such attributes have values other than -1 or auto. Successful validation guarantees that the signal has the attributes that you intended it to have.

You can create a Simulink.Signal object in the MATLAB® workspace or in a model workspace.

Use signal objects to assign or validate signal or discrete state attributes by giving the signal or discrete state the same name as the workspace variable that references the Simulink.Signal object.

For more information about using signal objects, see Use Simulink.Signal Objects to Specify and Control Signal Attributes and Data Objects.

To assign or validate the properties of signals based on an application-specific type, such as wind velocity, use a Simulink.ValueType object.

Creation

Create a Simulink.Signal object:

Description

example

signalObj = Simulink.Signal returns a Simulink.Signal object with default property values.

Properties

expand all

This property is read-only.

Information used by Simulink® Coder™ software for generating code for this signal. The value of this property is a Simulink.CoderInfo object.

The storage class of a Simulink.Signal object in a model workspace must be 'Auto'.

For more information, see C Data Code Interface Configuration for Model Interface Elements (Simulink Coder) and Choose Storage Class for Controlling Data Representation in Generated Code (Embedded Coder).

Description of this signal. This field is intended for use in documenting this signal.

This property is used by the Simulink Report Generator and for code generation.

If you have an Embedded Coder® license, you can add the signal description as a comment for the variable declaration in generated code:

  • Specify a storage class for the signal object other than 'Auto'.

  • On the Code Generation > Comments pane of the model Configuration Parameters dialog box, select the model configuration parameter Simulink data object descriptions. For more information, see Simulink data object descriptions (Embedded Coder).

Example: 'This signal represents the rotation speed of the engine.'

Data Types: char | string

Character vector specifying the data type of this signal.

The default value, 'auto', specifies that the software should determine the data type.

You can specify a built-in data type, for example, 'uint8' or 'single'. For more options, see Data Types Supported by Simulink.

To specify a fixed-point data type, use the fixdt function. For example, specify 'fixdt(1,16,5)'.

To specify a custom data type, enter a MATLAB expression that specifies the type, for example, a base workspace variable that references a Simulink.NumericType object.

To specify an enumerated data type, use the name of the type preceded by Enum:. For example, specify 'Enum: myEnumType'.

To specify a Simulink.ValueType object as the data type, use the name of the object preceded by ValueType:. For example, specify 'ValueType: myValueType'.

To specify a Simulink.Bus object as the data type, use the name of the bus object preceded by Bus:. For example, specify 'Bus: myBusObject'. See Bus Support for details about what you need to do if you specify a bus object as the data type.

When you specify a Simulink.ValueType or Simulink.Bus object as the data type, some properties of the Simulink.Signal object are ignored. For example, the Min, Max, and Unit properties of the Simulink.Signal object are ignored. The software uses the corresponding properties of the Simulink.ValueType object or Simulink.BusElement objects in the Simulink.Bus object instead.

Example: 'auto'

Example: 'int8'

Example: 'fixdt(1,16,5)'

Example: 'myAliasTypeObject'

Example: 'Enum: myEnumType'

Example: 'ValueType: myValueType'

Example: 'Bus: myBusObject'

Tips

When you edit the data type interactively, to display the Data Type Assistant, click the Show data type assistant button . For more information, see Specify Data Types Using Data Type Assistant.

Data Types: char | string

Minimum value that this signal can have.

The default value is [] (unspecified). Specify a finite, real, double, scalar value.

The software uses this value in these ways:

  • When updating the diagram or starting a simulation, the software generates an error if the initial value of the signal is less than the minimum value or if the minimum value is outside the range for the data type of the signal.

  • When you enable the Simulation range checking diagnostic, the software alerts you during simulation if the signal value is less than the minimum value (see Simulation range checking).

Example: -0.92

Dependencies

The software ignores the value of this property when DataType specifies a Simulink.ValueType or Simulink.Bus object. The software uses the minimum values specified by the Simulink.ValueType object or the Simulink.BusElement objects in the Simulink.Bus object instead.

Tips

For signal objects with a fixed-point data type, dialog boxes show the stored integer Minimum property, which is the minimum value that the signal should have, specified as a stored integer value. The value is derived from the real-world minimum value.

Data Types: double

Maximum value that this signal can have.

The default value is [] (unspecified). Specify a finite, real, double, scalar value.

The software uses this value in these ways:

  • When updating the diagram or starting a simulation, the software generates an error if the initial value of the signal is greater than the maximum value or if the maximum value is outside the range of the data type of the signal.

  • When you enable the Simulation range checking diagnostic, the software alerts you during simulation if the signal value is greater than the maximum value (see Simulation range checking).

Example: 5.32

Dependencies

The software ignores the value of this property when DataType specifies a Simulink.ValueType or Simulink.Bus object. The software uses the maximum values specified by the Simulink.ValueType object or the Simulink.BusElement objects in the Simulink.Bus object instead.

Tips

For signal objects with a fixed-point data type, dialog boxes show the stored integer Maximum property, which is the maximum value that the signal should have, specified as a stored integer value. The value is derived from the real-world maximum value.

Data Types: double

Physical unit used for expressing this signal value, for example, inches.

For more information, see Unit Specification in Simulink Models.

Example: 'degC'

Dependencies

The software ignores the value of this property when DataType specifies a Simulink.ValueType or Simulink.Bus object. The software uses the units specified by the Simulink.ValueType object or the Simulink.BusElement objects in the Simulink.Bus object instead.

Data Types: char | string

Scalar or vector specifying the dimensions of this signal.

Valid values are -1 (default) specifying any dimensions, N specifying a vector signal of size N, or [M N] specifying an MxN matrix signal.

To use symbolic dimensions, specify a character vector.

Example: [1 3]

Example: '[1 myDimParam]'

Dependencies

The software ignores the value of this property when DataType specifies a Simulink.ValueType object. The software uses the dimensions specified by the Simulink.ValueType object instead.

Data Types: double | char | string

Dimensions mode of the signal. Valid values are:

  • 'auto' — Allows variable-size and fixed-size signals.

  • 'Fixed' — Allows only fixed-size signals. Does not allow variable-size signals.

  • 'Variable' — Allows only variable-size signals.

For information about variable-size signals, see Variable-Size Signal Basics.

Dependencies

The software ignores the value of this property when DataType specifies a Simulink.ValueType or Simulink.Bus object. The software uses the dimensions modes specified by the Simulink.ValueType object or the Simulink.BusElement objects in the Simulink.Bus object instead.

Character vector specifying the numeric type of this signal. Valid values are 'auto', 'real', or 'complex'.

The default value, 'auto', specifies that the software should determine the complexity.

Dependencies

The software ignores the value of this property when DataType specifies a Simulink.ValueType or Simulink.Bus object. The software uses the complexity specified by the Simulink.ValueType object or the Simulink.BusElement objects in the Simulink.Bus object instead.

Rate at which the value of this signal should be updated.

See Specify Sample Time for details.

Example: 0.001

Example: 2

Data Types: double

Signal or state value before a simulation takes its first time step.

You can specify any MATLAB expression, including the name of a workspace variable, that evaluates to a numeric scalar value or array.

At the MATLAB Command Window or in a script, even if you use a number, specify the initial value as a character vector.

mySigObject.InitialValue = '5.3';
mySigObject.InitialValue = 'myNumericVariable';

To specify an initial value for a signal that uses a numeric data type other than double, cast the initial value to the signal data type. For example, you can specify 'single(73.3)' to use 73.3 as the initial value for a signal of data type single.

If you use a bus object as the data type for the signal object, set InitialValue to a character vector containing either 0 or a MATLAB structure that matches the bus object. See Bus Support for details.

If the initial value evaluates to a MATLAB structure, in the Configuration Parameters dialog box, set Underspecified initialization detection to Simplified.

If necessary, the software converts the initial value to ensure type, complexity, and dimension consistency with the corresponding block parameter value. If you specify an invalid value or expression, an error message appears when you update the model. Also, the software performs range checking of the initial value. The software alerts you when the initial value of the signal lies outside a range that corresponds to its specified minimum and maximum values and data type.

Classic initialization mode: In this mode, initial value settings for signal objects that represent these signals and states override the corresponding block parameter initial values if undefined (specified as []):

  • Output signals of conditionally executed subsystems and Merge blocks

  • Block states

Simplified initialization mode: In this mode, if a signal object is attached to the signal line connected to the Outport block of a conditionally executed subsystem, the software uses the initial value from the Simulink.Signal object.

Example: '15.23'

Example: 'myInitParam'

Data Types: char | string

Examples

collapse all

To use a signal object to control the characteristics of a signal in a model, create the object in a workspace and use the same name as the signal.

Create a signal object named mySig.

mySig = Simulink.Signal;

Set the data type of the signal object to 'boolean'.

mySig.DataType = 'boolean';

Get a handle to the block port that creates the target signal.

portHandles = get_param('myModel/myBlock','portHandles');
outportHandle = portHandles.Outport;

Specify the name of the output signal to match the name of the signal object. Use the 'Name' port parameter.

set_param(outportHandle,'Name','mySig')

Force the signal in the model to use the properties that the signal object stores by setting the 'MustResolveToSignalObject' port parameter to 'on'.

set_param(outportHandle,'MustResolveToSignalObject','on')

To use a signal object to control the characteristics of a signal in a model, create the object in a workspace and use the same name as the signal.

Create a signal object named mySig.

mySig = Simulink.Signal;

Set the data type of the signal object to 'boolean'.

mySig.DataType = 'boolean';

Specify the name of the output signal to match the name of the signal object. Use the 'SignalName' block parameter.

set_param('myModel/myOutport','SignalName','mySig')

Force the signal in the model to use the properties that the signal object stores by setting the 'MustResolveToSignalObject' block parameter to 'on'.

set_param('myModel/myOutport','MustResolveToSignalObject','on')

You can use a signal object to control the characteristics of a block state, such as that of the Discrete-Time Integrator block.

Create a signal object named myState.

myState = Simulink.Signal;

Set the data type of the signal object to 'int16'.

myState.DataType = 'int16';

Specify the name of the state to match the name of the signal object. Use the 'StateName' block parameter.

set_param('myModel/myBlock','StateName','myState')

Force the state in the model to use the properties that the signal object stores by setting the 'StateMustResolveToSignalObject' block parameter to 'on'.

set_param('myModel/myBlock','StateMustResolveToSignalObject','on')

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a

expand all