Sort vector based on another - How?
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Annie
 le 29 Avr 2025
  
    
    
    
    
    Réponse apportée : Walter Roberson
      
      
 le 29 Avr 2025
            So lets say I have a vector with distances ranging from 1 to 5 , whole numbers.
l = [ 5 3 2 1]
Associated with this vector are random integer values.
k = [ 2 3 4 1]
I want to be able to sort I and the k vectors follow....
so
l = [ 1 2 3 5]
k = [1 4 3 2]
How do I do this?
0 commentaires
Réponse acceptée
  Walter Roberson
      
      
 le 29 Avr 2025
        l = [ 5 3 2 1]
k = [ 2 3 4 1]
[l_sorted, l_sortidx] = sort(l);
k_sorted = k(l_sortidx);
l_sorted
k_sorted
0 commentaires
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!

