Separating numbers from Nans for averaging in a wave

Hi, 

Let's say I have numeric 2D wave called data2D (3600rows x 240cols). Each column has some NaNs in it as well. By NaN what I mean is that there was no value in that row of the column, so I'm assuming it is a NaN. Kindly correct me if this assumption is incorrect. Now I have to generate average value for each column so I'm doing MatrixOp data2D_avg = averagecols(data2D). Here's my trouble: 

I found that I couldn't run MatrixOp on columns that contain NaN values in them somewhere. The output for that column is simply NaN. So I tried setting all NaNs to 0 by doing this: 

data2D= numtype(data2D[p][q])=2 ? 0 : data2D[p][q]    . This command though compiled, did not work and returned the same data2D as before. I don't understand why, kindly advise.  So I used for loop to set all such values to 0 and finally got the MatrixOp to work. 

The problem is that I determined during quality control that my averages are smaller than the correct values. Probably because "averagecols" is averaging over those zeros as well where there was actually no value. How can I run averagecols in such a way that it only averages over the rows that contain numeric values and that wouldn't need me to set NaNs to 0 to make it run? Please advise. 

Thanks a lot, 

Peeyush 

Wavestats with a subrange will ignore the NaNs.

 

This should set NaNs and Infs to zero:

data2D = numtype(data2D[p][q])!=0 ? 0 : data2D[p][q])

You need two =

data2D= numtype(data2D[p][q])==2 ? 0 : data2D[p][q]

x=2 gives x the value 2

x==2 checks if the value of x is 2

I think there is a MatrixOP command to remove NaNs

From MatrixOP help:

ReplaceNaNs(w, replacementVal)
    Replaces every occurance of NaN in the wave w with replacementVal . The wave w  retains its dimensionality. replacementVal  is converted to the same number type as w  which may cause truncation.

ReplaceNaNs() may not be appropriate in this application because it would move the mean towards zero.  I recommend using ZapNaNs() to remove the NaN entries without affecting the subsequent mean() etc.