cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-85678%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ESortieren%20Sie%20eine%20Matrix%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85678%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EAlle%2C%3CBR%20%2F%3E%20Gibt%20es%20eine%20M%C3%B6glichkeit%2C%20eine%20%C3%A4hnliche%20Funktionalit%C3%A4t%20wie%20die%20unten%20gezeigte%20zu%20erreichen%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EA%20%3D%20%5B10%20-12%204%208%3B%206%20-9%208%200%3B%202%203%2011%20-2%3B%201%201%209%203%5D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EWie%20kann%20ich%20beim%20Sortieren%20die%20urspr%C3%BCnglichen%20Positionen%20der%20Elemente%20beibehalten%3F%3C%2FP%3E%3CP%3EWenn%20ich%20beispielsweise%20jede%20Spalte%20der%20Matrix%20sortieren%20m%C3%B6chte%2C%20kann%20ich%20mir%20nur%20Folgendes%20vorstellen%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Efor(i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20cols(A)%2C%20i%20%2B%2B%2C%0A%20%20%20%20%20%20%20%20%20%20t%20%3D%20A%5B0%2Ci%5D%3B%20%0A%20%20%20%20%20%20%20%20%20%20t1%20%3D%20sort%20descending(t)%3B%20%0A%20%20%20%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EWie%20kann%20ich%20nun%20die%20urspr%C3%BCngliche%20Position%20der%20Elemente%20ermitteln%20und%20beibehalten%3F%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fwww.mathworks.com%2Fhelp%2Fmatlab%2Fref%2Fsort.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fwww.mathworks.com%2Fhelp%2Fmatlab%2Fref%2Fsort.html%3C%2FA%3E%20-%20In%20Matlab%20gibt%20es%20ein%20zweites%20Argument%20f%C3%BCr%20die%20Sortierfunktion%2C%20das%20den%20Index%20zur%C3%BCckgibt%3C%2FP%3E%3CP%3EEbenso%20k%C3%B6nnen%20Sie%20in%20R%20den%20Index%20beibehalten.%20Sie%20fragen%20sich%2C%20wie%20das%20in%20JMP%20am%20besten%20geht%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85714%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Matrix%20sortieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85714%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5358%22%20target%3D%22_blank%22%3E%40Mark_Bailey%3C%2FA%3E%20%2C%3CBR%20%2F%3E%20Danke%20sch%C3%B6n.%20Ich%20werde%20eine%20Anfrage%20an%20die%20Wunschliste%20senden%2C%20um%20hierf%C3%BCr%20eine%20vorgefertigte%20Funktion%20bereitzustellen.Ich%20hoffe%2C%20dass%20JMP%20in%20Zukunft%20eine%20M%C3%B6glichkeit%20finden%20wird%2C%20die%20Matrix%20nicht%20mehr%20durchlaufen%20zu%20m%C3%BCssen.%20Ich%20w%C3%BCrde%20gerne%20sehen%2C%20dass%20die%20apply()-Funktionsfamilie%20von%20R%20in%20JMP%20eingef%C3%BChrt%20wird.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85707%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Matrix%20sortieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85707%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EDiese%20Anpassung%20sollte%20funktionieren%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EA%20%3D%20%5B10%20-12%204%208%3B%206%20-9%208%200%3B%202%203%2011%20-2%3B%201%201%209%203%5D%3B%3CBR%20%2F%3E%3CBR%20%2F%3Esort%20matrix%20%3D%20Function(%20%7B%20m%20%7D%2C%20%7B%20t%2C%20b%3D%5B%5D%2C%20i%3D%5B%5D%20%7D%2C%3CBR%20%2F%3E%20For(%20j%20%3D%201%2C%20j%20%26lt%3B%3D%20N%20Cols(%20m%20)%2C%20j%2B%2B%2C%3CBR%20%2F%3E%20t%20%3D%20A%5B0%2Cj%5D%3B%3CBR%20%2F%3E%20b%20%7C%7C%3D%20Sort%20Descending(%20t%20)%3B%3CBR%20%2F%3E%20i%20%7C%7C%3D%20Matrix(%20Reverse(%20As%20List(%20Rank%20Index(%20t%20)%20)%20)%20)%3B%3CBR%20%2F%3E%20)%3B%3CBR%20%2F%3E%20Eval%20List(%20%7B%20b%2C%20i%20%7D%20)%3B%3CBR%20%2F%3E)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%7B%20B%2C%20I%20%7D%20%3D%20sort%20matrix(%20A%20)%3B%3CBR%20%2F%3E%3CBR%20%2F%3EShow(%20A%2C%20B%2C%20I%20)%3B%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85701%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Matrix%20sortieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85701%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5358%22%20target%3D%22_blank%22%3E%40Mark_Bailey%3C%2FA%3E%20%26amp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2687%22%20target%3D%22_blank%22%3E%20%40txnelson%3C%2FA%3E%20%2C%3CBR%20%2F%3E%20Ich%20verstehe%2C%20dass%20es%20f%C3%BCr%20Sie%20offensichtlich%20erscheint%2C%20dass%20Rank()%20das%20tut%2C%20was%20ich%20will.%20Hier%20ist%20jedoch%20ein%20Beispiel%20daf%C3%BCr%2C%20warum%20ich%20frage%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20Matlab%20passiert%20Folgendes%2C%20wenn%20Sie%20versuchen%2C%20eine%20Matrix%20zu%20sortieren.%20Es%20tut%20mir%20leid%2C%20dass%20ich%20dieses%20Beispiel%20von%20einer%20anderen%20Plattform%20%C3%BCbernommen%20habe.%20Ich%20habe%20versucht%2C%20das%20zu%20vermeiden%2C%20aber%20ich%20kann%20mir%20keinen%20besseren%20Weg%20vorstellen%2C%20um%20zu%20erkl%C3%A4ren%2C%20was%20ich%20suche.%20Wenn%20Sie%20sich%20also%20die%20Werte%20von%20%E2%80%9EI%E2%80%9C%20ansehen%2C%20bleiben%20die%20Indizes%20erhalten%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20557px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20557px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20557px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F14829iF7B1C147EB151292%2Fimage-dimensions%2F557x452%3Fv%3Dv2%22%20width%3D%22557%22%20height%3D%22452%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWenn%20ich%20nun%20genau%20das%20Gleiche%20in%20JMP%20machen%20wollte%2C%20ist%20das%20die%20Vorgehensweise%2C%20die%20Sie%20mir%20empfehlen%3F%20Ja%2C%20es%20bringt%20mir%20nicht%20das%20gleiche%20Ergebnis.%20Au%C3%9Ferdem%20w%C3%BCrde%20ich%20es%20begr%C3%BC%C3%9Fen%2C%20wenn%20ich%20f%C3%BCr%20so%20etwas%20keine%20Schleife%20verwenden%20m%C3%BCsste%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EA%20%3D%20%5B10%20-12%204%208%3B%206%20-9%208%200%3B%202%203%2011%20-2%3B%201%201%209%203%5D%3B%0A%0Afor(i%20%3D%201%20%2C%20i%20%26lt%3B%3D%20N%20Cols(A)%2C%20i%2B%2B%2C%0A%20%20t%20%3D%20A%5B0%2Ci%5D%3B%20%0A%20%20t1%20%3D%20Sort%20Descending(t)%3B%20%0A%20%20ranks%20%3D%20Rank(t)%3B%20%0A%20%20%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85698%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Matrix%20sortieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85698%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C3%84hm%2C%20es%20ist%20das%20Ranking-Bit%20...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85684%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Matrix%20sortieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85684%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2687%22%20target%3D%22_blank%22%3E%40txnelson%3C%2FA%3E%20%2C%3CBR%20%2F%3E%20Ich%20glaube%2C%20Sie%20beziehen%20sich%20auf%20den%20Inhalt%2C%20der%20auch%20hier%20behandelt%20wird%20%E2%80%93%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2F14%2Franking-and-sorting.shtml%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2F14%2Franking-and-sorting.shtml%3C%2FA%3E%20.%20Dies%20erweitert%20jedoch%20nicht%20die%20Erfassung%20der%20Indizes%2C%20nach%20denen%20ich%20w%C3%A4hrend%20der%20Sortierung%20suche.%20Hoffentlich%20%C3%BCbersehe%20ich%20nichts.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85681%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Matrix%20sortieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85681%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EWerfen%20Sie%20einen%20Blick%20auf%20%E2%80%9ERangfolge%20und%20Sortierung%E2%80%9C%20im%20Abschnitt%20%E2%80%9EDatenstrukturen%2C%20Matrizen%E2%80%9C%20des%20Skripthandbuchs%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

Sort a matrix

All, 
     Is there a way to achieve functionality similar to what is shown below :

 

A = [10 -12 4 8; 6 -9 8 0; 2 3 11 -2; 1 1 9 3]

    Upon sorting, how can i retain the original positions of the elements ? 

    For e.g. if i wanted to sort each column of the matrix, I can only think of doing the following: 

 

for(i = 1, i <= N cols(A), i ++,
          t = A[0,i]; 
          t1 = sort descending(t); 
    );

    Now, how can I determine the original position of the elements and retain them ? 
    https://www.mathworks.com/help/matlab/ref/sort.html - In Matlab, there is a second argument to the sort function which returns the index 

     Similarly in R, you can retain the index. Wondering what is the best way to do that in JMP ?

Best
Uday
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Sort a matrix

This adaption should work:

 

A = [10 -12 4 8; 6 -9 8 0; 2 3 11 -2; 1 1 9 3];

sort matrix = Function( { m }, { t, b=[], i=[] },
For( j = 1, j <= N Cols( m ), j++,
t = A[0,j];
b ||= Sort Descending( t );
i ||= Matrix( Reverse( As List( Rank Index( t ) ) ) );
);
Eval List( { b, i } );
);

{ B, I } = sort matrix( A );

Show( A, B, I );

 

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Sort a matrix

Take a look at "Ranking and Sorting" in the "Data Structures, Matrices" section of the Scripting Guide
Jim
uday_guntupalli
Level VIII

Re: Sort a matrix

@txnelson
         I believe you are referring to the content that is also covered here - https://www.jmp.com/support/help/14/ranking-and-sorting.shtml . However, this does not expand on capturing the indices that I am looking for while performing the sort. Hopefully, I am not missing something. 

Best
Uday

Re: Sort a matrix

Um, it is the ranking bit...

uday_guntupalli
Level VIII

Re: Sort a matrix

@Mark_Bailey & @txnelson
    I understand that it looks obvious to you that Rank() does what I want, however , here is an example of why I am asking for: 

 

In Matlab, here is what happen when you try to sort a matrix. Apologies for pulling this example from a different platform, I tried to avoid doing that but I can't think of a better way to explain what I am after. So if you look at the values of  "I", it retains the indices 

image.png

 

Now, if I wanted to do the exact samething in JMP , is this the way you are recommending me to take, it yes, it doesn't get me the same result. Also, I would appreciate not having to use a loop for something like this

 

A = [10 -12 4 8; 6 -9 8 0; 2 3 11 -2; 1 1 9 3];

for(i = 1 , i <= N Cols(A), i++,
		t = A[0,i]; 
		t1 = Sort Descending(t); 
		ranks = Rank(t); 
   );

 

Best
Uday

Re: Sort a matrix

This adaption should work:

 

A = [10 -12 4 8; 6 -9 8 0; 2 3 11 -2; 1 1 9 3];

sort matrix = Function( { m }, { t, b=[], i=[] },
For( j = 1, j <= N Cols( m ), j++,
t = A[0,j];
b ||= Sort Descending( t );
i ||= Matrix( Reverse( As List( Rank Index( t ) ) ) );
);
Eval List( { b, i } );
);

{ B, I } = sort matrix( A );

Show( A, B, I );

 

uday_guntupalli
Level VIII

Re: Sort a matrix

@Mark_Bailey
    Thank you. I will submit a request to the wish list to provide a canned function for this.  I hope in the future, JMP will come up with a way to not have to loop through the matrix. I would love to see the apply() function family from R introduced into JMP. 

Best
Uday

Recommended Articles