Sort and Arrange Matrix for Lookup Table - monotonically increasing
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I want to prepare my data for a lookup table. It must be monotonically increasing: How can I do that ?
For example:
Before:
NAN 6 1 8 3 12 10 9
8 Q O R P U T S
1 C A D B G F E
4 J H K I N M L
13 L J M K P O N
9 X V Y W B A Z
12 E C F D I H G
After:
NAN 1 3 6 8 9 10 12
1 A B C D E F G
4 H I J K L M N
8 O P Q R S T U
9 V W X Y Z A B
12 C D E F G H I
13 J K L M N O P
0 commentaires
Réponse acceptée
Walter Roberson
le 24 Juil 2015
After = sortrows(sortrows(Before).').';
4 commentaires
Guillaume
le 27 Juil 2015
@Marv, Walter's answer does exactly as you want (assuming your data is just a matrix of numbers, unlike your example). It first sorts the rows by the first column, then the columns by the first rows. NaN does not have an ordering, so sortrows puts it at the end.
If you want the NaN row/column to come first, simply replace the NaN by -Inf.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!