Sort Matrix according to another Vector
Afficher commentaires plus anciens
I have two sets of data such as:
A = [1 3 4 7 2]';
B = [3 4 7 1 2; 1 2 3 4 5; 6 7 8 9 10]';
Since B first column has the same values as A, but in different order, my question is if it is possible to sort B in a way that the resulting matrix is:
B = [1 3 4 7 2; 4 1 2 3 5; 9 6 7 8 10]';
Réponse acceptée
Plus de réponses (1)
A = [1 3 4 7 2]';
B_origin = [3 4 7 1 2; 1 2 3 4 5; 6 7 8 9 10]';
% Since B first column has the same values as A, but in different order,
% my question is if it is possible to sort B in a way that the resulting matrix is:
B_corrct = [1 3 4 7 2; 4 1 2 3 5; 9 6 7 8 10]';
[~,Locb] = ismember(A,B_origin(:,1))
B_origin(Locb,:)
B_origin(Locb,:) == B_corrct
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!