How to eliminate Inf and NaN in array?

  • Follow


Hi,

Assuming there are ten values of which some are probably Inf or NaN in one array A(10). I want to eliminate Inf and NaN to calculate the average value. At first the numbers of Inf and NaN value should be found. For example, there are 2 Inf and 2 NaN values found in the array, then the average is obtained by the sum of the rest of values divided by 6 (the # of rest of values). How to program this code? Thanks a lot.
0
Reply Zhengyu 1/11/2011 11:40:20 PM

On 11-01-11 05:40 PM, Zhengyu Jiang wrote:

> Assuming there are ten values of which some are probably Inf or NaN in one
> array A(10). I want to eliminate Inf and NaN to calculate the average value.
> At first the numbers of Inf and NaN value should be found. For example, there
> are 2 Inf and 2 NaN values found in the array, then the average is obtained by
> the sum of the rest of values divided by 6 (the # of rest of values). How to
> program this code? Thanks a lot.

mean(A(isfinite(A)))

Note: isfinite is false for nan as well as -inf and +inf .
0
Reply I 1/11/2011 11:52:20 PM


1 Replies
1080 Views

(page loaded in 0.009 seconds)

Similiar Articles:













7/20/2012 1:08:26 PM


Reply: