Sort Matrix according to another Vector
Mostrar comentarios más antiguos
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]';
Respuesta aceptada
Más respuestas (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
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!