开发者

summing vector having cells=inf values

开发者 https://www.devze.com 2023-04-02 01:01 出处:网络
I need to find out the average of the values Columns 1 through 17 0.3108开发者_运维百科0.7273Inf0.2878-0.09470.1286-0.31080.56340.28220.2362-0.26280.0960-0.1675-0.0934-0.1710-0.3077-0.2726

I need to find out the average of the values

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

How do I exclude the inf?


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

or mean(a(a<inf)).


To find how many are Inf:

1) find the 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) Find the number of 0s == Inf

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

Is there another way?

0

精彩评论

暂无评论...
验证码 换一张
取 消