Simulink.ValueType - Specify common set of signal properties for reuse - MATLAB (original) (raw)
Specify common set of signal properties for reuse
Since R2021b
Description
A Simulink.ValueType
object is a common set of signal properties that you define once and reuse for each signal that represents the same value type. For example, you can specify the unit, minimum value, maximum value, and dimensions of wind velocity, tire pressure, or water temperature once and reuse that specification.
To create and modify Simulink.ValueType
objects in the base workspace or a data dictionary, you can use the Type Editor, Model Explorer, or MATLAB® commands. You cannot store Simulink.ValueType
objects in model workspaces.
Use a Simulink.ValueType
object to specify signal properties for these blocks and objects:
- Inport block
- Outport block
- In Bus Element block
- Out Bus Element block
- Signal Specification block
- Constant block (since R2023b)
- Simulink.BusElement objects
- Simulink.Signal objects (since R2023a)
- Simulink.Parameter objects (since R2023a)
Use Simulink.ValueType
objects to validate the properties of a signal and enforce consistency between connected blocks at an interface.
Creation
You can create a Simulink.ValueType
object several ways.
- Interactively create a value type using the Type Editor orModel Explorer.
- Programmatically create a value type using the
Simulink.ValueType
function described here.
Syntax
Description
`vt` = Simulink.ValueType
returns aSimulink.ValueType
object with default property values.
Properties
Data type, specified as a character vector or string scalar.
You can specify any of these options:
- Built-in Simulink® data type — For example, specify
'single'
or'uint8'
. See Data Types Supported by Simulink. - Fixed-point data type — Use the fixdt function. For example, specify
'fixdt(1,16,0)'
. - Enumerated data type — Use the name of the type preceded by
Enum:
. For example, specify'Enum: myEnumType'
. - Custom data type — Use a MATLAB expression that specifies the type. For example, you can specify aSimulink.NumericType object whose
DataTypeMode
property is set to a value other than'Fixed-point: unspecified scaling'
. - Bus data type — Use the name of a Simulink.Bus object preceded by
Bus:
. For example, specify'Bus: myBusObject'
.
When you specify a Simulink.Bus
object as the data type, some properties of the Simulink.ValueType
object are ignored. For example, theMin
, Max
, and Unit
properties of the Simulink.ValueType
object are ignored. The software uses the corresponding properties of the Simulink.BusElement
objects in theSimulink.Bus
object instead.
Data Types: char
| string
Minimum value, specified as a finite real double scalar.
Dependencies
The software ignores the value of this property when DataType
specifies a Simulink.Bus
object. The software uses the minimum values specified by the Simulink.BusElement
objects in theSimulink.Bus
object instead.
Data Types: double
Maximum value, specified as a finite real double scalar.
Dependencies
The software ignores the value of this property when DataType
specifies a Simulink.Bus
object. The software uses the maximum values specified by the Simulink.BusElement
objects in theSimulink.Bus
object instead.
Data Types: double
Physical unit, specified as a character vector or string scalar.
For more information, see Unit Specification in Simulink Models.
Example: 'inches'
Dependencies
The software ignores the value of this property when DataType
specifies a Simulink.Bus
object. The software uses the units specified by the Simulink.BusElement
objects in theSimulink.Bus
object instead.
Data Types: char
| string
Numeric type, specified as 'real'
or'complex'
.
Dependencies
The software ignores the value of this property when DataType
specifies a Simulink.Bus
object. The software uses the complexity specified by the Simulink.BusElement
objects in theSimulink.Bus
object instead.
Data Types: char
| string
Dimensions, specified as a scalar or vector.
Tips
To specify an array of buses, set DataType
to aSimulink.Bus
object and Dimensions
to the dimensions of the array.
Data Types: double
Option to allow only fixed-size or variable-size signals, specified as'Fixed'
or 'Variable'
, respectively.
Dependencies
The software ignores the value of this property when DataType
specifies a Simulink.Bus
object. The software uses the dimensions modes specified by the Simulink.BusElement
objects in theSimulink.Bus
object instead.
Data Types: char
| string
Description, specified as a character vector or string scalar. Use the description to document information about the Simulink.ValueType
object, such as the kind of signal it applies to. This information does not affect Simulink processing.
Data Types: char
| string
Examples
In the MATLAB Command Window, define a reusable set of properties that correspond to wind velocity by using the Simulink.ValueType
function.
Create a ValueType
object with default properties.
windVelocity = Simulink.ValueType
windVelocity = ValueType with properties:
DataType: 'double'
Min: []
Max: []
Unit: ''
Complexity: 'real'
Dimensions: 1
DimensionsMode: 'Fixed'
Description: ''
Specify the desired property values for wind velocity.
windVelocity.DataType = 'single'; windVelocity.Min = 11; windVelocity.Max = 17; windVelocity.Unit = 'm/s'; windVelocity.Dimensions = [2 4 3]; windVelocity.Description = 'Wind velocity value type'
windVelocity = ValueType with properties:
DataType: 'single'
Min: 11
Max: 17
Unit: 'm/s'
Complexity: 'real'
Dimensions: [2 4 3]
DimensionsMode: 'Fixed'
Description: 'Wind velocity value type'
To define a recurring type of value that you model as an array of buses, use a Simulink.ValueType
object with a Simulink.Bus
object data type and nonscalar dimensions.
Create a Simulink.Bus
object that represents red, green, and blue (RGB) color values. Name it RGB
.
r = Simulink.BusElement; r.Name = 'r';
g = Simulink.BusElement; g.Name = 'g';
b = Simulink.BusElement; b.Name = 'b';
RGB = Simulink.Bus; RGB.Elements = [r g b];
Create a Simulink.ValueType
object that represents an image. Name it myImage
.
myImage = Simulink.ValueType;
Assign the bus object named RGB
as the data type of myImage
.
myImage.DataType = 'Bus: RGB';
Specify that the value type represents a matrix of RGB values by setting the dimensions of myImage
to a matrix.
myImage.Dimensions = [1024 1024];
When you use the myImage
value type in a model, it defines an array of buses. For more information about arrays of buses, see Group Nonvirtual Buses in Arrays of Buses.
Version History
Introduced in R2021b