Effacer les filtres
Effacer les filtres

How to sort vector with respect to another vector

2 vues (au cours des 30 derniers jours)
Vishal Sharma
Vishal Sharma le 3 Fév 2017
Commenté : Matin Salehi le 12 Juil 2019
I have one vector
A= [11; 12; 13; 21; 22; 31] A = 11 12 13 21 22 31
And another vector B = [5; 2; 1; 3; 4; 6] B = 5 2 1 3 4 6
I want results in new matrix with rankings as per vector B and values of A vector, so that result shall be 22 12 11 13 21 31

Réponse acceptée

Guillaume
Guillaume le 3 Fév 2017
What you're asking is simple indexing:
A = [11; 12; 13; 21; 22; 31];
B = [5; 2; 1; 3; 4; 6]
result = A(B)
  1 commentaire
Matin Salehi
Matin Salehi le 12 Juil 2019
hi, I would b grateful if you help me regarding this question. how can I rank a matrix for example A = [ 12 14 16;15 18 20; 12 78 98] with a vector B = [2 1 3]
that the answer be like : the scond column of A come first, and the first column of A move to second column, and then 3? like C= [ 14 12 16; 18 15 20; 68 12 98]

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