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
orauto
) by the signal source.Validate signal attributes whose values are explicitly assigned by the signal source. Such attributes have values other than
-1
orauto
. 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:
By using the Model Data Editor. See For Signals.
By using the Model Explorer. See Create Data Objects from Built-In Data Class Package Simulink.
Directly from a signal properties dialog box or the Property Inspector in a model. See Create Signal Object from Signal Properties Dialog Box.
By using the
Simulink.Signal
function described here.
Description
signalObj = Simulink.Signal
returns a
Simulink.Signal
object with default property values.
Properties
CoderInfo
— Specifications for generating code for signal
Simulink.CoderInfo
object
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
— Custom description of signal
''
(default) | character vector | string scalar
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
DataType
— Data type of signal
'auto'
(default) | character vector | string scalar
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
Min
— Minimum value of signal
[]
(default) | real double
scalar
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
Max
— Maximum value of signal
[]
(default) | real double
scalar
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
Unit
— Physical unit of signal value
''
(default) | character vector | string scalar
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
Dimensions
— Dimensions of signal
-1
(default) | row vector | character vector | string scalar
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
DimensionsMode
— Dimension mode of signal
'auto'
(default) | 'Fixed'
| 'Variable'
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.
Complexity
— Numeric complexity of signal
'auto'
(default) | 'real'
| 'complex'
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.
SampleTime
— Sample time of signal
-1
(default) | double
scalar or array
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
InitialValue
— Initial value of signal or state
''
(default) | character vector | string scalar
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
Create Signal Object for Signal at Block Port
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')
Create Signal Object for Signal at Root-Level Outport Block
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')
Create Signal Object for State
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
To control the appearance of a Simulink.Signal
object in the
generated code, use the Storage class property.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced before R2006aR2023b: Simulink.ValueType
objects do not override description of parent
When you specify a Simulink.ValueType
object as the data type of a
Simulink.Signal
object, the value type object no longer overrides the description
of the Simulink.Signal
object.
See Also
Simulink.Parameter
| Simulink.CoderInfo
| AUTOSAR.Signal
(AUTOSAR Blockset)
Topics
- Use Simulink.Signal Objects to Specify and Control Signal Attributes
- Determine Where to Store Variables and Objects for Simulink Models
- Control Data Types of Signals
- C Data Code Interface Configuration for Model Interface Elements (Simulink Coder)
- Define Data Classes
- Signal Basics
- Data Objects
- Data Types Supported by Simulink
- MPT Data Object Properties (Embedded Coder)
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)