Sorting wave based on scaled x values

Hi All,

I was wondering if there is a way to sort a wave based on the scaled x values. I have to concatenate some waves together but they are not in the correct order but each will have a scaling that could be used to sort the values. I can't figure out the command that can accomplish this, anybody have any suggestions?

Best,
Paul
This function will take in a list of waves and return a string with a new list of the waves in order of X scaling XOffset value:
Function/S sortWavesByXScale(wlist)
    String wlist
   
    Variable nwaves = ItemsInList(wlist)
    Make/FREE/N=(nwaves) xlist
   
    xlist = DimOffset($StringFromList(p, wlist), 0)
    Make/N=(nwaves)/FREE xindices
    makeIndex xlist, xindices
   
    String newlist = ""
    Variable i
    for (i = 0; i < nwaves; i += 1)
        newlist += StringFromList(xindices[i], wlist)+";"
    endfor
   
    return newlist
end

Example:
make w1, w2, w3
setscale/P x 0,1,w1
setscale/P x 1,1,w3
setscale/P x 2,1,w2
print sortWavesByXScale(WaveList("w*", ";", ""))
  w1;w3;w2;


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com