Matlab ||sum function application || sum函数使用

format:

First .sum(name of data carrier(matrix of vector)[1], number)  (数据载体,数字,以下用"[1]”代替) 

number: could be omitted  ,equals to effect of number "1"  数字可省略,相当于 下面的数字为“1”所述效果

if number is "1", this cmd calcuate the sum of eleent row by column , 数字为 1,则分别按列求和

"2", then summarize elements by column by row 数字为2,按行

"3"  summarize along vertical direction ,applied in 3-D array .为3,则按“z”轴 ,也就是求和对象中每一组竖直方向的数组求和。用于3维数组

Second. sum([1],[number1,number2]

this means several calculation ,it calculate as the rule of the first number and(not the next adjacent number) the second one .

for example :

D(:,:,1) =

     1     1     1     1
     1     1     1     1
     1     1     1     1


D(:,:,2) =

     1     2     3     4
     5     6     7     8
     9    10    11    12

 sum(D,[1,2])

ans(:,:,1) =

    12


ans(:,:,2) =

    78

we can know

sum(D,1)

ans(:,:,1) =

     3     3     3     3


ans(:,:,2) =

    15    18    21    24
they are new row ,the second calculation aims at them

 sum(D,[1,3])

ans =

    18    21    24    27

_________________________________

 

another example for format one 

 sum(D,3)

ans =

     2     3     4     5
     6     7     8     9
    10    11    12    13

Third.add specific statement  .format:

sum ([1],'___‘)

they can be  "all"  means that summarize all elements once as to be one result

     'includenan' - the sum of a vector containing NaN values is also NaN. 含数据缺失,则 此列求和无效(输出 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.                  忽略缺失的数据,对现有数据求和

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

(quoted from matlab file)

数据类型,第一个对任何类型数据 操作后 输出 double 型,第二个输出原来类型,第三个比较特殊

只要是浮点型(包括double 和single)则输出原来一样的类型,

不是浮点型,输出double型

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值