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 #45417 is a reply to message #45415] Thu, 08 September 2005 07:38 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
KJM writes:

> 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

I think your basic idea is great. :-)

Here is what I would do.

C = (A + B) / 2
indices = WHERE(A EQ 0 AND B NE 0, count)
IF count GT 0 THEN C[indices] = B
indices = WHERE(A NE 0 AND B EQ 0, count)
IF count GT 0 THEN C[indices] = A

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[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 18 02:39:03 PDT 2025

Total time taken to generate the page: 1.36128 seconds