sum
fi
数组元素的总和
说明
示例
创建一个 fi
向量,并在构造函数中指定 fimath
属性。
A = fi([1 2 5 8 5], 'SumMode', 'KeepLSB', 'SumWordLength', 32)
A = 1 2 5 8 5 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11 RoundingMethod: Nearest OverflowAction: Saturate ProductMode: FullPrecision SumMode: KeepLSB SumWordLength: 32 CastBeforeSum: true
计算 A
的元素的总和。
S = sum(A)
S = 21 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 11 RoundingMethod: Nearest OverflowAction: Saturate ProductMode: FullPrecision SumMode: KeepLSB SumWordLength: 32 CastBeforeSum: true
输出 S
是标量,其 SumWordLength
指定为 32
。S
的 FractionLength
是 11
,因为 SumMode
设置为 KeepLSB
。
创建一个 fi
数组,并计算每列中元素的总和。
A=fi([1 2 8;3 7 0;1 2 2])
A = 1 2 8 3 7 0 1 2 2 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11
S=sum(A)
S = 5 11 10 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 11
MATLAB® 返回一个行向量,其中包含 A
中每列的总和。S
的 WordLength
增大了两位,因为 ceil(log2(size(A,1)))=2
。FractionLength
保持不变,因为 SumMode
的默认设置是 FullPrecision
。
沿 3×3 矩阵 A
的第二个维度 (dim=2
) 计算总和。
A=fi([1 2 8;3 7 0;1 2 2])
A = 1 2 8 3 7 0 1 2 2 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11
S=sum(A, 2)
S = 11 10 5 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 11
MATLAB® 返回一个由每行中元素的总和组成的列向量。S
的 WordLength
是 18,因为 ceil(log2(size(A,2)))=2
。
计算 A
的列的总和,并使输出数组 S
具有与之相同的数据类型。
A = fi([1 2 8;3 7 0;1 2 2])
A = 1 2 8 3 7 0 1 2 2 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11
class(A)
ans = 'embedded.fi'
S = sum(A, 'native')
S = 5 11 10 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 11
class(S)
ans = 'embedded.fi'
MATLAB® 保留了 A
的数据类型,并返回 embedded.fi
类型的行向量 S
。
输入参数
fi
输入数组,指定为标量、向量、矩阵或多维数组。
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
复数支持: 是
运算维度,指定为正整数标量。dim
也可以是 fi
对象。如果未指定值,则默认值是大小不等于 1 的第一个数组维度。
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
输出类,指定为 'double'
或 'native'
。输出类定义执行运算和返回运算时所用的数据类型。
如果
type
是'double'
,则sum
返回双精度数组,而不考虑输入数据类型。如果
type
是'native'
,则sum
返回与输入数组A
具有相同类的数组。
数据类型: char
输出参量
总和数组,以标量、向量、矩阵或多维数组形式返回。
注意
fimath
对象用于计算总和。如果将 SumMode
设置为 FullPrecision
、KeepLSB
或 KeepMSB
,则 sum(A)
的整数增长位数为 ceil(log2(size(A,dim)))
。
限制
sum
不支持数据类型为Boolean
的fi
对象。
扩展功能
使用说明和限制:
仅当起控制作用的
fimath
对象的SumMode
属性设置为SpecifyPrecision
或KeepLSB
时,才支持可变大小的输入。
HDL 代码生成
使用 HDL Coder™ 为 FPGA 和 ASIC 设计生成 VHDL、Verilog 和 SystemVerilog 代码。
版本历史记录
在 R2006a 之前推出
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)