Wed, 02/20/2013 - 04:40 pm
I am looking for a quick method to average a specific range in several waves (hundreds of sweeps from electrophysiological recordings). Let's say each of my waves goes from 0 to 100 seconds in the X axis, I would like to average the Y value of the segment from 0 to 30 s from each sweep and place all the averages in a separate wave for further manipulation.
Can anybody suggest a quick command for this, without having to run
mean(waveName [, x1, x2 ] )
for every single wave?
Thanks
If you stored all your 1D waves as columns of a 2D matrix wave you can then define the range [x1,x2] using a mask wave (another 2D wave of the same dimensions with 0's in all rows outside [x1,x2]. The mean that you seek is then given by:
MatrixOP/O aa=sumCols(maskWave*dataWave)/numPointsInRange
February 20, 2013 at 05:09 pm - Permalink
String list // Semicolon-separated list of wave names in current data folder (e.g., "wave0;wave1;wave2;")
Variable startX, endX
String outputWaveName // Desired output wave name
Variable numWaves = ItemsInList(list)
Make /D /O /N=(numWaves) $outputWaveName // Overwrites !!!
Wave averages = $outputWaveName // Create local wave reference
Variable i
for(i=0; i<numWaves; i+=1)
String name = StringFromList(i, list)
Wave w = $name
averages[i] = mean(w,startX,endX)
endfor
End
That said, there are many advantages to storing 1D data as columns of a 2D wave such as reduced clutter and the ability to index a column in a simple fashion. You might consider adopting a 2D wave as your standard storage.
Columns of 2D waves can be graphed individually. You can also curve fit to them. For most other operations (e.g., Smooth, Integrate, Convolve) you would need to extract the column of interest to a 1D wave.
February 20, 2013 at 07:08 pm - Permalink
February 23, 2013 at 11:24 am - Permalink