
Sorting 2D waves, by using one column as a key

andyfaff
Function MDsort(w,keycol, [reversed]) Wave w variable keycol, reversed variable type type = Wavetype(w) make/Y=(type)/free/n=(dimsize(w,0)) key make/free/n=(dimsize(w,0)) valindex if(type == 0) Wave/t indirectSource = w Wave/t output = key output[] = indirectSource[p][keycol] else Wave indirectSource2 = w multithread key[] = indirectSource2[p][keycol] endif valindex=p if(reversed) sort/a/r key,key,valindex else sort/a key,key,valindex endif if(type == 0) duplicate/free indirectSource, M_newtoInsert Wave/t output = M_newtoInsert output[][] = indirectSource[valindex[p]][q] indirectSource = output else duplicate/free indirectSource2, M_newtoInsert multithread M_newtoinsert[][] = indirectSource2[valindex[p]][q] multithread indirectSource2 = M_newtoinsert endif End
=======Here is the original version=======
Function MDtextsort(w,keycol, [reversed]) Wave/t w variable keycol, reversed make/t/free/n=(dimsize(w,0)) key make/free/n=(dimsize(w,0)) valindex key[] = w[p][keycol] valindex=p if(reversed) sort/a/r key,key,valindex else sort/a key,key,valindex endif duplicate/free/t w, M_newtoInsert M_newtoinsert[][] = w[valindex[p]][q] duplicate/o/t M_newtoInsert,w End

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
May 13, 2009 at 05:40 am - Permalink
December 4, 2009 at 05:16 pm - Permalink
========
Time to find out, whether you are dead right, or just dead.
January 11, 2011 at 06:20 am - Permalink
Just in case someone finds that here. Since IP7 this can be done with the builtin SortColumns.
February 2, 2021 at 03:02 pm - Permalink