![](/profiles/wavemetrics/themes/wavemetrics/logo.png)
Average of all points in a bunch of 1D waves
![](/sites/default/files/styles/thumbnail/public/sjr51/profile-images/2018-07/cube.png?itok=iXDZATA2)
sjr51
//This function will find the average of all points for each 1D wave in a batch of waves and then put the result //into a new wave. So n waves will give a wave n points. //It requires a sensible root naming convention, e.g. cell1_veh_0, cell1_veh_1... //Use "opt" to specific "mean" or "median". Function AvgWaves(root,opt) //call example AvgWaves("cell1_veh","mean") String root String opt String rootstar=root + "*" String wavenames=wavelist(rootstar,";","") //gets the wavelist of batch of waves String ResultWave="W_" + opt + "_" + root String LabelWave="T_" + opt + "_" + root Variable nwaves =ItemsInList(wavenames) Make /O/N=(nwaves) $ResultWave //average values will go in this wave Make /O/T/N=(nwaves) $LabelWave //wave names will go in this textwave Wave w0 = $ResultWave Wave/T wT = $LabelWave Variable i Variable tempvar String name if (stringmatch(opt,"mean")==1) For (i = 0; i < nwaves; i += 1) name = StringFromList(i,wavenames) Wave /z w1 = $name Duplicate /o w1 tempwave //not required WaveTransform zapnans, tempwave //not required tempvar=mean(tempwave) w0[i]=tempvar wT[i]=name Killwaves tempwave endfor elseif (stringmatch(opt,"median")==1) For (i = 0; i < nwaves; i += 1) name = StringFromList(i,wavenames) Wave /z w1 = $name Duplicate /o w1 tempwave WaveTransform zapnans, tempwave tempvar=StatsMedian(tempwave) w0[i]=tempvar wT[i]=name Killwaves tempwave endfor else //error message Print "Select mean or median (in quotes) for opt" return 0 Endif End
![](/sites/default/files/forum.png)
Forum
![](/sites/default/files/support.png)
Support
![](/sites/default/files/gallery.png)
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More