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 #45414 is a reply to message #45413] Thu, 08 September 2005 07:55 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"KJM" <kimberlite@gmail.com> writes:
> 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).

Here's something without WHERE's

MISSING = 0.0
C = (A+B)/((A NE MISSING) + (B NE MISSING))

You'll get NaN whereever both values are missing. This is easily
extendible to the case where you have N arrays with M values each.
Just arrange them into an MxN array,

DATA = DBLARR(M,N)
... fill data values ...
C = TOTAL(DATA,2)/TOTAL(DATA NE MISSING,2)

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[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: Fri Oct 10 23:06:42 PDT 2025

Total time taken to generate the page: 0.85922 seconds