Main Content

Simulink.ValueType

Specify properties of signals based on application-specific value types

Since R2021b

Description

ASimulink.ValueTypeobject is an application-specific set of 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.

To create and modifyValueTypeobjects in the base workspace or a data dictionary, you can use theModel Exploreror MATLAB®commands. You cannot storeValueTypeobjects in model workspaces.

指定一个ValueTypeobject:

  • At an interface withInport,Outport,In Bus Element, orOut Bus Elementblocks

  • In a model withSignal Specificationblocks

  • In aSimulink.BusElement,Simulink.Signal, orSimulink.Parameterobject

UseValueTypeobjects to validate the properties of a signal and enforce consistency between connected blocks at an interface.

Creation

You can create aSimulink.ValueTypeobject several ways.

  • Interactively create a value type using theType EditororModel Explorer.

  • Programmatically create a value type using theSimulink.ValueTypefunction described here.

Description

example

vt= Simulink.ValueType返回一个ValueTypeobject with default property values.

Properties

expand all

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”. SeeData Types Supported by Simulink.

  • Fixed-point data type — Use thefixdtfunction. For example, specify'fixdt(1,16,0)'.

  • Enumerated data type — Use the name of the type preceded by枚举:. For example, specify'Enum: myEnumType'.

  • Custom data type — Use a MATLAB expression that specifies the type. For example, you can specify aSimulink.NumericTypeobject whoseDataTypeModeproperty is set to a value other than'Fixed-point: unspecified scaling'.

  • Bus data type — Use the name of aSimulink.Busobject preceded byBus:. For example, specify'Bus: myBusObject'.

When you specify aSimulink.Busobject as the data type, some properties of theSimulink.ValueTypeobject are ignored. For example, theMin,Max, andUnitproperties of theSimulink.ValueTypeobject are ignored. The software uses the corresponding properties of theSimulink.BusElementobjects in theSimulink.Busobject instead.

Data Types:char|string

Minimum value, specified as a finite real double scalar.

Dependencies

The software ignores the value of this property whenDataTypespecifies aSimulink.Busobject. The software uses the minimum values specified by theSimulink.BusElementobjects in theSimulink.Busobject instead.

Data Types:double

Maximum value, specified as a finite real double scalar.

Dependencies

The software ignores the value of this property whenDataTypespecifies aSimulink.Busobject. The software uses the maximum values specified by theSimulink.BusElementobjects in theSimulink.Busobject instead.

Data Types:double

Physical unit, specified as a character vector or string scalar.

For more information, seeUnit Specification in Simulink Models.

Example:'inches'

Dependencies

The software ignores the value of this property whenDataTypespecifies aSimulink.Busobject. The software uses the units specified by theSimulink.BusElementobjects in theSimulink.Busobject instead.

Data Types:char|string

数值类型, specified as'real'or'complex'.

Dependencies

The software ignores the value of this property whenDataTypespecifies aSimulink.Busobject. The software uses the complexity specified by theSimulink.BusElementobjects in theSimulink.Busobject instead.

Data Types:char|string

Dimensions, specified as a scalar or vector.

Tips

To specify an array of buses, setDataTypeto aSimulink.Bus对象和Dimensionsto 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 whenDataTypespecifies aSimulink.Busobject. The software uses the dimensions modes specified by theSimulink.BusElementobjects in theSimulink.Busobject instead.

Data Types:char|string

Description, specified as a character vector or string scalar. Use the description to document information about theValueTypeobject, such as the kind of signal it applies to. This information does not affect Simulink processing.

Data Types:char|string

Examples

collapse all

In the MATLAB Command Window, define a reusable set of properties that correspond to wind velocity by using theSimulink.ValueTypefunction.

创建一个ValueTypeobject 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 aSimulink.ValueTypeobject with aSimulink.Busobject data type and nonscalar dimensions.

创建一个Simulink.Busobject that represents red, green, and blue (RGB) color values. Name itRGB.

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];

创建一个Simulink.ValueTypeobject that represents an image. Name itmyImage.

myImage = Simulink.ValueType;

Assign the bus object namedRGBas the data type ofmyImage.

myImage.DataType ='Bus: RGB';

Specify that the value type represents a matrix of RGB values by setting the dimensions ofmyImageto a matrix.

myImage.Dimensions = [1024 1024];

When you use themyImagevalue type in a model, it defines an array of buses. For more information about arrays of buses, seeGroup Nonvirtual Buses in Arrays of Buses.

Version History

Introduced in R2021b