Sorting a matrix? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Sorting a matrix? (/thread-4176.html) |
Sorting a matrix? - DrD - 06-18-2015 01:48 PM Looking for ideas: I need to row sort M1, an (n x 4) matrix, in decreasing order of column 4. Then on decreasing order of column 2, if sorted M1 contains more than one row with equal column 4 values. How can this be done? Thanks, -Dale- RE: Sorting a matrix? - DrD - 06-18-2015 03:26 PM This is bulky, but seems to work (better ideas?): Code:
tnx, -Dale- RE: Sorting a matrix? - parisse - 06-19-2015 04:54 AM Create a sort function, something like f:=(x,y)->if y[4]!=x[4] then return x[4]>y[4] else return x[2]>y[2] end; then sort(m,f) will sort a matrix m using f as a sort function. RE: Sorting a matrix? - DrD - 06-19-2015 10:28 AM Thank you for your very helpful suggestion! I like compact solutions like this, and I'll add it to my "how to" list for future reference. -Dale- |