quantize
使用 quantizer
对象量化数值数据
说明
使用 y
= quantize(q
,x
)quantizer
对象 q
来量化 x
。
当
x
是数值数组时,x
的每个元素均经过量化。输出y
以内置双精度值形式返回。当
x
是元胞数组时,该元胞数组的每个数值元素都经过量化。输出y
的字段以内置双精度形式返回。当
x
是结构体时,x
的每个数值字段均经过量化。输出y
的字段以内置双精度形式返回。
quantize
不会更改 x
的非数值元素或字段,也不会对非数值发出警告。
在对 quantize
的调用期间中,quantizer
对象状态 max
、min
、noverflows
、nunderflows
和 noperations
会更新,并且在调用 reset
前会保留滚动总数。
示例
将数据量化为自定义精度浮点类型
使用 quantize
将数据量化为自定义精度浮点类型。
x = linspace(-15,15,1000); q = quantizer('float','floor',[6 3]); range(q)
ans = 1×2
-14 14
y = quantize(q,x);
Warning: 68 overflow(s) occurred in the fi quantize operation.
plot(x,y); title(tostring(q))
量化为定点类型
使用 quantize
将数据量化为定点类型,字长为 6 位,小数长度为 2 位,向下舍入,溢出时绕回。
x = linspace(-15,15,1000); q = quantizer('fixed','floor','wrap',[6 2])
q = DataMode = fixed RoundMode = floor OverflowMode = wrap Format = [6 2]
range(q)
ans = 1×2
-8.0000 7.7500
y = quantize(q,x);
Warning: 468 overflow(s) occurred in the fi quantize operation.
plot(x,y); title(tostring(q))
使用 quantize
将数据量化为定点类型,字长为 3 位,小数长度为 2 位,收敛舍入,溢出时绕回。
q = quantizer('fixed','convergent','wrap',[3 2]); x = (-2:eps(q)/4:2)'; y = quantize(q,x);
Warning: 33 overflow(s) occurred in the fi quantize operation.
plot(x,[x,y],'.-'); title(tostring(q)); axis square
输入参数
q
— 用于量化的数据类型属性
quantizer
对象
用于量化的数据类型属性,指定为 quantizer
对象。
示例: q = quantizer('fixed','ceil','saturate',[5 4]);
x
— 要量化的数据
标量 | 向量 | 矩阵 | 多维数组 | 元胞数组 | 结构体
要量化的数据,指定为标量、向量、矩阵、多维数组、元胞数组或结构体。
当
x
是数值数组时,x
的每个元素均经过量化。当
x
是元胞数组时,该元胞数组的每个数值元素都经过量化。当
x
是结构体时,x
的每个数值字段均经过量化。
quantize
不会更改 x
的非数值元素或字段,也不会对非数值发出警告。
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| struct
| cell
复数支持: 是
x1,x2,…
— 要量化的数据(作为单独的元素)
标量 | 向量 | 矩阵 | 多维数组 | 元胞数组 | 结构体
要量化的数据(作为单独的元素),指定为标量、向量、矩阵、多维数组、元胞数组或结构体。
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| struct
| cell
复数支持: 是
输出参数
版本历史记录
在 R2012b 中推出R2021b: quantize
函数舍入行为的更改
在以前的版本中,quantize
将对范围
内的值向正无穷舍入,对范围 realmax
< input < realmax + 0.5*eps
(realmax)-realmax > x > -realmax - 0.5*eps
内的值向负无穷舍入。从 R2021b 开始,根据使用的舍入方法,这些范围内的值量化如下。
舍入方法 | 范围 realmax < input < realmax + 0.5*eps(realmax) 内的值舍入到 | 范围 -realmax > x > -realmax - 0.5*eps 内的值舍入到 |
---|---|---|
floor | realmax (适用于 x < realmax + eps ) | -Inf |
ceil | Inf | -realmax (适用于 x > -realmax - eps ) |
round | realmax | -realmax |
convergent | realmax | -realmax |
fix | realmax (适用于 x < realmax + eps ) | -realmax (适用于 x > -realmax - eps ) |
nearest | realmax | -realmax |
另请参阅
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)