Effacer les filtres
Effacer les filtres

how to sort matrix according to another matrix in matlab

1 vue (au cours des 30 derniers jours)
Jothi
Jothi le 1 Nov 2012
I have a two matrix
A=[ 1 2 3;
2 1 4;
1 3 2; ]
and
B=[1 2 3]
i want the output matrix like,
C =[1 2 3;
1 2 4;
1 2 3]
how to get this output. The matrix A is sorted according to the matrix B.
Thanks.
  4 commentaires
Jothi
Jothi le 2 Nov 2012
Modifié(e) : Jothi le 2 Nov 2012
A is First matrix (3x3 matrix).
A=[ 1 2 3;
2 1 4;
1 3 2; ]
B is another matrix (1x3 Matrix) ie.,
B=[1 2 3]
Based on B I want to sort each row in Matrix A.
C is the output matrix (3x3 Matrix)
C =[1 2 3;
1 2 4;
1 2 3]
here each row is sorted according the matrix B.
Azzi Abdelmalek
Azzi Abdelmalek le 2 Nov 2012
Modifié(e) : Azzi Abdelmalek le 2 Nov 2012
what if B=[1 3 2] what should be C

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 1 Nov 2012
Modifié(e) : Azzi Abdelmalek le 1 Nov 2012
sort(A,2)
gives the result but had nothing to do with B
maybe you want this
C=sort(A,2)
C=C(:,B)

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices 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!

Translated by