Re: Removing unwanted data from a structure [message #84250 is a reply to message #84137] |
Fri, 10 May 2013 15:10   |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On 5/10/13 12:41, cab581 wrote:
> OK, I'll back track and try to explain more clearly.
> I have a structure called STRUCT, it is made from thousands of files, each of these has a measurement at a particular location. The first six tags STRUCT.(0) to STRUCT.(5) are identifiers, STRUCT.(6) is the data. First, I put the data in to 18 latitudinal bins;
>
> FOR I = 0,17 DO BEGIN
> A = 0.0
> A = WHERE(STRUCT.LAT GT LAT[I] AND STRUCT.LAT LE LAT[I]+10)
>
> STRUCT[A].(6) is therefore the data that I want to analyze in each of the 18 bins.
>
> I found the medians by using;
>
> FOR J = 0,99 DO BEGIN
>
> MEDIAN[I,J] = MEDIAN(STRUCT[A].(6)[J], /double, /even)
>
> Where I is the latitude (0,17) and J is the altitude (0,99), so I get an array of the median measurement at each of my 18x100 points.
>
> What I want to do is sift through the data from which I calculated the median and then compare those to the median to exclude erroneous values, so I thought that I could use the following;
>
> ind = where(STRUCT[A].(6)[J] GT (MEDIAN+1000))
> IF ind[0] GT 0 then STRUCT[A].(6)[ind] = !values.F_Nan
>
> but it doesn't work, I end up with NaNs all over the place where they shouldn't be.
>
Aha! I think I understand. I was missing the part about binning in latitude.
The three problems I see with the code as you've written it are:
1. You're using the names of language elements ("median", "struct")
as variable names. While this is not forbidden and won't cause errors,
it is very confusing and will almost certainly lead you into writing
buggy code. So I'm going to pretend that your "median" variable is
actually called "med".
2. In this comparison:
ind = where(STRUCT[A].(6)[J] GT (MEDIAN+1000))
you want med[i,j].
3. You're indexing the wrong part of the struct here:
IF ind[0] GT 0 then STRUCT[A].(6)[ind] = !values.F_Nan
I think you actually want:
if ind[0] gt 0 then struct[ind].(6)[j] = !values.f_nan
-Jeremy.
|
|
|