Sorting two simple matrices

1 vue (au cours des 30 derniers jours)
Jonathan Moorman
Jonathan Moorman le 23 Fév 2021
Commenté : Jonathan Moorman le 23 Fév 2021
Hi! I need to sort matrix A from least to greatest; however, the values are tied to matrix B. How can I can make B adjust with a matrix A sort.
Matrix A and B are the starting values, and A' and B' are the desired answer.
A = [ 2, 3, 1, 4]
B = [ 6, 5, 1, 10]
A' = [ 1, 2 , 3, 4]
B' = [ 1, 6, 5, 10]

Réponse acceptée

James Tursa
James Tursa le 23 Fév 2021
Modifié(e) : James Tursa le 23 Fév 2021
Use the 2nd output argument of the sort( ) function, which has the indexing. E.g.,
[Asorted,ix] = sort(A);
Bsorted = B(ix);
  1 commentaire
Jonathan Moorman
Jonathan Moorman le 23 Fév 2021
Works great. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by