Function TwoDDecimate() //Decimate XY pair //Do not have to be in order as they are temporarily sorted //**Bins by equal # of points, not by equal spaced ranges** String YdWaveName, XdWaveName Variable Loop1, Loop2, Bins=50, BinSize Prompt YdWaveName, "Y Wave", popup, WaveList("*",";","DIMS:1,TEXT:0,WIN:")+WaveList("*",";","DIMS:1,TEXT:0") Prompt XdWaveName, "X Wave", popup, WaveList("*",";","DIMS:1,TEXT:0,WIN:")+WaveList("*",";","DIMS:1,TEXT:0") Prompt Bins, "Bins" DoPrompt "2D Decimate", YdWaveName, XdWaveName, Bins Duplicate /O $YdWaveName, $(YdWaveName+"_sorted") Duplicate /O $XdWaveName, $(XdWaveName+"_sorted") Wave YdWave=$(YdWaveName+"_sorted"), XdWave=$(XdWaveName+"_sorted") Sort XdWave XdWave,YdWave Make /O/N=(Bins) $(YdWaveName+"_decimated")=0, $(XdWaveName+"_decimated")=0 Wave DecY=$(YdWaveName+"_decimated"), DecX=$(XdWaveName+"_decimated") BinSize=trunc((numpnts(YdWave)-1)/Bins)+1 //-1 and +1 to handle non-even sorting into bins //If it's a perfect multiple, -1 means you will get one fewer/bin, and the +1 gets you back //If there is a remainder, the -1 has no effect and the +1 puts one more in each bin so there won't be a remainder //(but there will be a smaller number in the last bin) for (Loop1=0;Loop1