主要内容

数据类型转换

Convert input signal to specified data type

  • Library:
  • Simulink / Commonly Used Blocks

    金宝appsimulink /信号属性

    HDL编码器 /常用块

    HDL Coder / HDL Floating Point Operations

    HDL Coder / Signal Attributes

  • 数据类型转换block

描述

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 issingleand 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

用一个数据类型转换以下列出信号的块如下:

  1. 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.

  2. 将任何整数类型的信号投向枚举类型的信号。

    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.

端口

输入

展开全部

输入signal, specified as a scalar, vector, matrix, or N-D array. The input can be any real- or complex-valued signal. If the input is real, the output is real. If the input is complex, the output is complex. The block converts the input signal to the输出数据类型you specify.

When you are converting fixed-point data types, use the输入and output to have equalparameter to determine whether the conversion happens based on theReal World Value (RWV)orStored Integer (SI)value of the signal. For more information, seeConvert Fixed-Point Signals

数据类型:single|双倍的|half|int8|INT16|INT32|INT64|UINT8|UINT16|uint32|uint64|布尔|fixed point|枚举

Output

展开全部

Output signal, converted to the data type you specify, with the same dimensions as the input signal.

数据类型:single|双倍的|half|int8|INT16|INT32|INT64|UINT8|UINT16|uint32|uint64|布尔|fixed point|枚举

Parameters

展开全部

Lower value of the output range that Simulink checks.

Simulink uses the minimum to perform:

Note

Output minimumdoes not saturate or clip the actual output signal. Use the饱和取而代之的是。

Programmatic Use

块参数:OutMin
类型: character vector
Values:'[]'|标量
Default:'[]'

模拟检查的输出范围的上值。金宝app

Simulink uses the maximum value to perform:

Note

最大输出does not saturate or clip the actual output signal. Use the饱和取而代之的是。

Programmatic Use

块参数:OutMax
类型: character vector
Values:'[]'|标量
Default:'[]'

选择输出的数据类型。可以继承,直接指定或表示为数据类型对象,例如Simulink.NumericType

Programmatic Use

块参数:OutdatatyPest
类型:角色向量
Values:'Inherit: Inherit via back propagation'|'double'|'单身的'|'一半'|'int8'|'uint8'|'int16'|'uint16'|'int32'|'uint32'|'int64'|'uint64'|fixdt(1,16)'|'fixdt(1,16,0)'|'FIXDT(1,16,2^0,0)'|'Enum: '''
Default:'Inherit: Inherit via back propagation'

Select this parameter to prevent the fixed-point tools from overriding theOutputdata type you specify on the block. For more information, seeUse Lock Output Data Type Setting(定点设计师)

Programmatic Use

块参数:LockScale
类型:角色向量
Values:'离开'|'on'
Default:'离开'

在固定点数据表示的背景下,指定哪种类型的输入和输出必须相等。

  • Real World Value (RWV)— Specifies the goal of making theReal World Value (RWV)of the input equal to theReal World Value (RWV)of the output.

  • Stored Integer (SI)— Specifies the goal of making theStored Integer (SI)value of the input equal to theStored Integer (SI)输出的值。

Programmatic Use

块参数:convertrealworld
类型:角色向量
Values:'Real World Value (RWV)' | 'Stored Integer (SI)'
Default:'Real World Value (RWV)'

Choose one of these rounding modes.

Ceiling

正向无穷大。等效于MATLAB®ceilfunction.

Convergent

回合数字为最近的代表值。如果发生领带,则将圆形到最近的整数。等效于定点Designer™convergentfunction.

地面

Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLABfloorfunction.

Nearest

回合数字为最近的代表值。If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Designernearestfunction.

Round

回合数字为最近的代表值。If a tie occurs, rounds positive numbers toward positive infinity and rounds negative numbers toward negative infinity. Equivalent to the Fixed-Point Designer圆形的function.

最简单

Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.

回合数字为零。等效于MATLABfixfunction.

Programmatic Use

块参数:RndMeth
类型: character vector
Values:'天花板'|'Convergent'|'Floor'|“最近”|'Round'|'Simplest'|'Zero'
Default:'Floor'

See Also

有关更多信息,请参阅Rounding(定点设计师)

Specify whether overflows saturate or wrap.

  • off— Overflows wrap to the appropriate value that the data type can represent.

    For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.

  • on— Overflows saturate to either the minimum or maximum value that the data type can represent.

    For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.

Tip

  • 当您的模型有可能溢出时,请考虑选择此复选框,并且您需要在生成的代码中进行明确的饱和保护。

  • 当您要优化生成的代码效率时,请考虑清除此复选框。

    清除此复选框还可以帮助您避免过度指定块如何处理范围的信号。有关更多信息,请参阅Troubleshoot Signal Range Errors

  • 选择此复选框时,饱和度适用于块上的每个内部操作,而不仅仅是输出或结果。

  • In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Programmatic Use

块参数:SaturateOnIntegerOverflow
类型:角色向量
Values:'离开'|'on'
Default:'离开'

Specify the sample time as a value other than-1。有关更多信息,请参阅Specify Sample Time

Dependencies

This parameter is not visible unless it is explicitly set to a value other than-1。To learn more, see块for Which Sample Time Is Not Recommended

Programmatic Use

块参数:SampleTime
类型:string scalar or character vector
Default:“ -1”

块特征

Data Types

布尔|双倍的|枚举|fixed point|half|integer|single

Direct Feedthrough

是的

多维信号

是的

可变大小信号

是的

零-Crossing Detection

no

扩展功能

C/C ++代码生成
使用Simulink®Coder™生成C和C ++代码。金宝app

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
使用定点Designer™设计和模拟定点系统。

Version History

Introduced before R2006a