Splitting waves based on value in one wave
Soepvork
I have a set of waves which I want to split based on the value for that point in one particular wave. Basically, I have multiple waves which contain my data, and one wave which contains an id-number to distinguish between different data set. Based on that id-number, I'd like to cut the large multiple waves (containing data for all sets) into smaller waves containing a single data set.
Let's say I have two data waves, wave_x and wave_y, and an wave with the id-number, wave_id. Based on the value of a point in wave_id, I'd like to separate the waves. In particular, the values of my wave_id are of three types: it's a 2, it's dividable by 6, or it's dividable by 6 once you add 2 to the value (so either 2, 6n, or 4+6n)
Now, I want to split wave_x and wave_y into three seperate sets (6 waves): one wave_x and wave_y for id=2, one of each for id=6n, and one each for id=4+6n.
Does anyone know if there is an easy way to do that?
Many thanks,
Stanley
The following function should help you out. Advanced Igor users will observe that it is inefficient due to the repeated calls to
Redimension
, but that is unlikely to be an issue unless you have very large waves.wave waveID, waveX, waveY
variable nPoints = DimSize(waveID, 0)
Make /O/N=0 /D W_2_X, W_2_Y
Make /O/N=0 /D W_n6_X, W_n6_Y
Make /O/N=0 /D W_n6_4_X, W_n6_4_Y
variable i
for (i = 0; i < nPoints; i+=1)
if (waveID[i] == 2) // 2
Redimension /N=(DimSize(W_2_X, 0) + 1) W_2_X, W_2_Y
W_2_X[DimSize(W_2_X, 0) - 1] = waveX[i]
W_2_Y[DimSize(W_2_X, 0) - 1] = waveY[i]
elseif (mod(waveID[i], 6) == 0) // 6n
Redimension /N=(DimSize(W_n6_X, 0) + 1) W_n6_X, W_n6_Y
W_n6_X[DimSize(W_n6_X, 0) - 1] = waveX[i]
W_n6_Y[DimSize(W_n6_Y, 0) - 1] = waveY[i]
elseif (mod(waveID[i] - 4, 6) == 0) // 6n + 4
Redimension /N=(DimSize(W_n6_4_X, 0) + 1) W_n6_4_X, W_n6_4_Y
W_n6_4_X[DimSize(W_n6_4_X, 0) - 1] = waveX[i]
W_n6_4_Y[DimSize(W_n6_4_Y, 0) - 1] = waveY[i]
endif
endfor
End
September 16, 2011 at 11:32 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 16, 2011 at 12:08 pm - Permalink