sum函数的用法(matlab)

摘自matlab

sum Sum of elements.
S = sum(X) is the sum of the elements of the vector X. If X is a matrix,
S is a row vector with the sum over each column. For N-D arrays,
sum(X) operates along the first non-singleton dimension.

S = sum(X,DIM) sums along the dimension DIM. 

S = sum(..., TYPE) specifies the type in which the 
sum is performed, and the type of S. Available options are:

'double'    -  S has class double for any input X
'native'    -  S has the same class as X
'default'   -  If X is floating point, that is double or single,
               S has the same class as X. If X is not floating point, 
               S has class double.

S = sum(..., MISSING) specifies how NaN (Not-A-Number) values are 
treated. The default is 'includenan':

'includenan' - the sum of a vector containing NaN values is also NaN.
'omitnan'    - the sum of a vector containing NaN values
               is the sum of all its non-NaN elements. If all 
               elements are NaN, the result is 0.

Examples:
If   X = [0 1 2; 3 4 5]
then sum(X, 1) is [3 5 7] and sum(X, 2) is [3; 12]

If X = int8(1:20) then sum(X) accumulates in double and the
result is double(210) while sum(X,'native') accumulates in
int8, but overflows and saturates to int8(127).

用法(翻译)

sum:元素的和。
S = sum(X) 是向量X的元素的和。如果X是一个矩阵,S是一个行向量(每一列的元素之和组成)。对于一个N*D的数组,sum(X) 沿着第一个非单例的维度进行操作。(??)>>操作之后发现sum(X)=sum(X,1)
S = sum(X,DIM):沿着某个维度来求和。>>sum(x,1)就是按列求和,生成一个行向量;sum(X,2)就是按行求和,生成一个列向量;sum(X,3),这里只要DIM大于等于3,得出来的结果都是X本身,因为平常用到的矩阵都是二维的(三维情况不同)。
S = sum(…, TYPE)将sum的结果专门指定某种格式,可以指定的种类有:
‘double’ - 对任意输入的X,S都是double型
‘native’ - S和X的型完全相同
‘default’ - 如果X是浮点型,那么不管X是双精度还是单精度型,S都和X型相同. 如果X不是浮点型,那么S是double型。

S = sum(…, MISSING)指定了NAN的值怎么运算,默认是includenan。
‘includenan’ - 包含了非数字量的向量的和任然是非数字量。
‘omitnan’ - the sum of a vector containing NaN values
is the sum of all its non-NaN elements. If all
elements are NaN, the result is 0.
(没搞懂,有空更正)

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值