comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: 2 arrays, average, missing data
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: 2 arrays, average, missing data [message #45413 is a reply to message #45412] Thu, 08 September 2005 08:24 Go to previous messageGo to previous message
Benjamin Luethi is currently offline  Benjamin Luethi
Messages: 22
Registered: December 2004
Junior Member
An short answer would be:

C = (A+B)/((A NE 0)+(B NE 0))

The divisor is 1+1=2 if both A and B are not 0.
0+1=1 if one of them is 0.
0+0=0 if both A and B are 0.

If A and B are integer, divison by zero produces 0, which is the wanted
result.
If A or B are of type double or float, the third case produces NaN.
Convert it
to zero using:

sel = where(finite(C,/NaN),count)
if count gt 0 then C[sel] = 0

Ben


On Thu, 08 Sep 2005 16:18:44 +0200, KJM <kimberlite@gmail.com> wrote:

> HI All,
> IDL newbie here, I would appreciate any help. (Have been pouring over
> Gumley and Fanning books for a day now, can't get this simple
> calculation done.)
>
> I have 2 arrays. Each array has float values and missing
> data(value=0). I want to create a third array that has the average of
> the two arrays if there are two good values. Otherwise, I want the
> third array to take the value of the array that has data.
>
>
> If my arrays are A and B, and the new array C, I know I can use:
>
> C = (A+B)/2
>
> to get the third array with averaged values. The only problem, is
> that missing data values are averaged in with good values also. (ie:
> 275 averaged w/ 0 -- when I want to just take the 275 value).
>
> Have tried If statements, -- but I realize these are all for scalar
> values, not array.
>
> My basic idea is:
>
> If A = 0, C = B
> If B = 0, C = A
> If A and B EQ 0, C = 0
> If A and B NE 0, C = (A+B)/2
>
>
>
>
> Any help appreciated!
> Thanks.
>



--
-------------+
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Ordered index array
Next Topic: Re: Postscript colour sampler?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 10:41:44 PDT 2025

Total time taken to generate the page: 0.72137 seconds