averaging parts of a wave --> write in a new wave

Hi all,

I would like to average different parts of a wave and write the results in a new wave. The data wave looks like:

{a,a,a,a,a,b,b,b,c,c,c,c,d,d,d,d,d, ..., a,a,a,a,a,b,b,b,c,c,c,c,d,d,d,d,d}

So, the different block of data to average have different number of points, and this sequence of blocks repeats all along the wave.

The final wave should be {avg_a,avg_b, avg_c, avg_d, ...., avg_a,avg_b, avg_c, avg_d}. The point is that I would like also to remove the first point in the a-block, b-block, c-block and d-block when doing the average.

Could you please help me with this? I do not have an easy way to do it ....

Thank you,
T



Do you know how many points are in each block?
Do you know how many blocks there are?
Does the wave have unit scaling?
andyfaff wrote:
Do you know how many points are in each block?
Do you know how many blocks there are?
Does the wave have unit scaling?



1. no. of points in each block is known (for example a->5, b->3, c->4, d->5 points in the block)
2. yes, this is also known (in principle this is the no. of point in the row data scan, for each point measured with four different parameters, from here the resulting a,b,c,d blocks)
3. no

thanks!
This should do it.
#pragma rtGlobals=3     // Use modern global access method.
Function stuffarooney(data, block_lengths)
    Wave data, block_lengths

    variable ii, jj
    duplicate/free data, temp_data
    setscale /P x, 0, 1, temp_data
    make/d/o/n=0 output
    ii = 0
    for(; numpnts(temp_data) ; )
        jj = mod(ii, numpnts(block_lengths))
        redimension/n=(dimsize(output, 0) + 1) output
   
        output[ii] = mean(temp_data, 1, block_lengths[jj] - 1)
        ii += 1
        deletepoints 0, block_lengths[jj], temp_data
    endfor

End