Basically, I think I Need to change the way of comparing/sorting values in each column... Instead of only sorting after the first numeric value, it should take the whole number into consideration... Btw the underlying datatype of the column data is double. If I look for methods(jtable) I get a list with all possible methods. Still I cannot figure out how to adjust the sorting order (perhaps sth. with Comparator...)
Sort Numbers correctly in an uitable
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey guys,
I want to sort the numbers this way (e.g. 145 129 90 2 -1) inside my uitable htable. Instead the following code sorts the numbers in that way (-1 129 145 2 90). It´s obvious that the program is just sorting after the first numeric value. Has someone got a clue about how to sort these numbers right? Below you will find the current code, which implements the sorting (Credits to Yair Altman).
Many thanks in advance!
% Display the uitable and get its underlying Java object handle
jscrollpane = findjobj(hTable);
jtable = jscrollpane.getViewport.getView;
% Now turn the JIDE sorting on
jtable.setSortable(true);
jtable.setAutoResort(true);
jtable.setMultiColumnSortable(true);
jtable.setPreserveSelectionsAfterSorting(true);
Risposte (1)
Stephen23
il 4 Giu 2018
Modificato: Stephen23
il 4 Giu 2018
I am sure that you could find some Java add-on that provides this functionality, but if you want to sort strings with numeric values then basically you will need to get the table values, convert to numeric (if required), sort, and then apply that sort order to the contents of the table.
If the data are a cell array of strings (char vectors) then one way of doing this would be to download my FEX submission natsortrows:
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!