数据类型转换
Convert input signal to specified data type
- Library:
Simulink / Commonly Used Blocks
金宝appsimulink /信号属性
HDL编码器 /常用块
HDL Coder / HDL Floating Point Operations
HDL Coder / Signal Attributes
描述
The数据类型转换block converts an input signal of any Simulink®data type to the data type that you specify.
Note
通过指定块参数来控制输出数据类型,或从下游块继承数据类型,请使用数据类型转换block. To inherit a data type from a different signal in the model, use the数据类型转换Inheritedblock.
Convert Fixed-Point Signals
When you convert between fixed-point data types, the输入and output to have equal参数控制块行为。当以下内容时,此参数不会改变块的行为。
The input and output do not have a fixed-point data type.
The input or output has a fixed-point data type with trivial scaling.
For more information about fixed-point numbers, seeFixed-Point Numbers in Simulink(定点设计师)。
To convert a signal from one data type to another by attempting to preserve the real-world value of the input signal, selectReal World Value (RWV)
,默认设置。该块说明了输入和输出的缩放范围所施加的限制,并尝试生成相等的现实世界值的输出。
要通过执行存储整数值的缩放重新解释来更改输入信号的现实世界值,请选择Stored Integer (SI)
。Within the limits of the specified data types, the block attempts to preserve the stored integer value of the signal during conversion. A best practice is to specify input and output data types using the same word length and signedness. Doing so ensures that the block changes only the scaling of the signal. Specifying a different signedness or word length for the input and output could produce unexpected results such as range loss or unexpected sign extensions. For an example, see转换Simulink模型中的数据类型金宝app。
如果您选择Stored Integer (SI)
, the block does not perform a lower-level bit reinterpretation of a floating-point input signal. For example, if the input issingle
and has value5
, the bits that store the input in memory are given in hexadecimal by the following command.
num2hex(single(5))
40a00000
However, the数据类型转换block does not treat the stored integer value as40a00000
, but instead as the real-world value,5
。After conversion, the stored integer value of the output is5
。
Cast Enumerated Signals
用一个数据类型转换以下列出信号的块如下:
To cast a signal of enumerated type to a signal of any numeric type.
The underlying integers of all enumerated values input to the数据类型转换block must be within the range of the numeric type. Otherwise, an error occurs during simulation.
将任何整数类型的信号投向枚举类型的信号。
The value input to the数据类型转换块必须匹配枚举值的基本值。否则,在模拟过程中会发生错误。
您可以启用整数溢出饱和parameter so that Simulink uses the default value of the enumerated type when the value input to the block does not match the underlying value of an enumerated value. See类型Casting for Enumerations(Simulink Coder)。
你不能使用数据类型转换block in these cases:
To cast a noninteger numeric signal to an enumerated signal.
无论复杂信号的真实部分和虚构部分的数据类型如何,要向枚举的信号施放复杂的信号。
SeeSimulink Enumerationsfor information on working with enumerated types.
端口
输入
Output
Parameters
Model Examples
块特征
Data Types |
|
Direct Feedthrough |
|
多维信号 |
|
可变大小信号 |
|
零-Crossing Detection |
|