求和矢量有cell = inf值

时间:2011-09-03 19:47:13

标签: matlab

我需要找出值的平均值

Columns 1 through 17

    0.3108    0.7273       Inf    0.2878   -0.0947    0.1286   -0.3108    0.5634    0.2822    0.2362   -0.2628    0.0960   -0.1675   -0.0934   -0.1710   -0.3077   -0.2726

Columns 18 through 20

   -0.0630   -0.5097    0.1823

如何排除inf?

2 个答案:

答案 0 :(得分:4)

>> a=[0.3108    0.7273       Inf    0.2878   -0.0947    0.1286   -0.3108    0.5634    0.2822    0.2362   -0.2628    0.0960   -0.1675   -0.0934   -0.1710   -0.3077   -0.2726 -0.0630 -0.5097 0.1823];
>> mean(a(~isinf(a)))

ans =

    0.0295

mean(a(a<inf))

答案 1 :(得分:-1)

要查找Inf的数量:

1)找到infs

Allvalues{1}<inf                    
ans =
     1     1     0     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

2)找到0的数量== Inf

sum(~(Allvalues{1}<inf))
ans =
     1

还有其他办法吗?